Thread overview | |||||
---|---|---|---|---|---|
|
April 19, 2020 How to use import std.algorithm.iteration.permutations? | ||||
---|---|---|---|---|
| ||||
Hi When I try to build the following: import std.algorithm.iteration; void test(int[] array); void main() { int[] a = [1,1,2,2,3,3]; foreach (p; a.permutations) { test(p); } } I get the error: .\permutations_example.d(10): Error: function permutations_example.test(int[] array) is not callable using argument types (Indexed!(int[], ulong[])) .\permutations_example.d(10): cannot pass argument p of type Indexed!(int[], ulong[]) to parameter int[] array What's the proper way to obtain the array of permutations of a? Kind regards David |
April 19, 2020 Re: How to use import std.algorithm.iteration.permutations? | ||||
---|---|---|---|---|
| ||||
Posted in reply to David Zaragoza | On Sunday, 19 April 2020 at 17:57:21 UTC, David Zaragoza wrote:
> Hi
>
> When I try to build the following:
>
> import std.algorithm.iteration;
>
> void test(int[] array);
>
> void main()
> {
> int[] a = [1,1,2,2,3,3];
> foreach (p; a.permutations)
> {
> test(p);
> }
> }
>
> I get the error:
>
> .\permutations_example.d(10): Error: function permutations_example.test(int[] array) is not callable using argument types (Indexed!(int[], ulong[]))
> .\permutations_example.d(10): cannot pass argument p of type Indexed!(int[], ulong[]) to parameter int[] array
>
> What's the proper way to obtain the array of permutations of a?
>
> Kind regards
> David
`permutation()` returns a lazy range (i.e an iterator). To turn a permutation into a concrete data type use .array on each one.
---
void test(int[] array){}
void main()
{
int[] a = [1,1,2,2,3,3];
foreach (p; a.permutations)
{
test(p.array);
}
}
---
|
April 19, 2020 Re: How to use import std.algorithm.iteration.permutations? | ||||
---|---|---|---|---|
| ||||
Posted in reply to Basile B. | On Sunday, 19 April 2020 at 20:25:23 UTC, Basile B. wrote:
> On Sunday, 19 April 2020 at 17:57:21 UTC, David Zaragoza wrote:
>> [...]
>
> `permutation()` returns a lazy range (i.e an iterator). To turn a permutation into a concrete data type use .array on each one.
>
> ---
> void test(int[] array){}
>
> void main()
> {
> int[] a = [1,1,2,2,3,3];
> foreach (p; a.permutations)
> {
> test(p.array);
> }
> }
> ---
forgot to put the imports:
---
import std.algorithm.iteration, std.array;
---
|
Copyright © 1999-2021 by the D Language Foundation