canFind doesn't work on Array, replacing [] with array doesn't work, etc...

ag0aep6g via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 18 10:46:26 PDT 2016


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));
}
----


More information about the Digitalmars-d-learn mailing list