canFind doesn't work on Array, replacing [] with array doesn't work, etc...
Joerg Joergonson via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Sat Jun 18 14:52:16 PDT 2016
On Saturday, 18 June 2016 at 17:46:26 UTC, ag0aep6g wrote:
> On Saturday, 18 June 2016 at 17:02:40 UTC, Joerg Joergonson
> wrote:
>> 3. can't use canFind from algorithm. Complains it can't find a
>> matching case. I tried many variations to get this to work.
>
> canFind takes a range. Array isn't a range itself, but you can
> get one by slicing it with []:
>
> ----
> import std.container.array;
> import std.algorithm;
> void main()
> {
> Array!int a = [1, 2, 3];
> assert(a[].canFind(2));
> assert(!a[].canFind(0));
> }
> ----
Thanks. I've decided to implement a wrapper around Array so it is
a drop in replacement for [].
More information about the Digitalmars-d-learn
mailing list