Re: Checking all elements are unique.

2016-08-31 Thread pineapple via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: Checking all elements are unique.

2016-08-31 Thread Rene Zwanenburg via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 08:38:11 UTC, Andrea Fontana wrote: Something like this: https://dpaste.dzfl.pl/9fa55b2a7927 ? Andrea Or use findAdjacent: auto idsAreUnique = ids.array.sort.findAdjacent.empty; http://dlang.org/phobos/std_algorithm_searching.html#.findAdjacent

Re: Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
@Edwin: Thank you for the insight about indexed range. @Adrea: Thanks, this looks good. Even if I found it a little obscure at first sight, it's better than my previous solution.

Re: Checking all elements are unique.

2016-08-31 Thread Andrea Fontana via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Re: Checking all elements are unique.

2016-08-31 Thread Edwin van Leeuwen via Digitalmars-d-learn
On Wednesday, 31 August 2016 at 07:40:39 UTC, Dorian Haglund wrote: Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C

Checking all elements are unique.

2016-08-31 Thread Dorian Haglund via Digitalmars-d-learn
Hello, I have an array of objects of class C which contain a id member. I want to figure out if all the id members are unique using functional primitives. For example, if I have: class C { int id; } and an array of C 'Cs'; My idea was to do: auto ids = Cs.map!(c => c.id);