How to search for an element in the array. D2 phobos.
Eldar Insafutdinov
e.insafutdinov at gmail.com
Sun Jul 12 14:14:21 PDT 2009
I am a little bit confused with a simple operation of searching in the array with D2-phobos. With tango I used to use:
size_t find( Elem[] buf, Elem pat, Pred2E pred = Pred2E.init );
Performs a linear scan of buf from [0 .. buf.length), returning the index of the first element matching pat, or buf.length if no match was found. Comparisons will be performed using the supplied predicate or '==' if none is supplied.
I tried std.algorithm.find:
class Node { ... }
Node[] v;
Node node;
...
int pos = find(v, node);
I get this error: /home/eldar/d/bin/../src/phobos/std/algorithm.d(1617): Error: no property 'empty' for type 'model_d2.Node'
I think I completely misunderstood how to use it.
Many thanks in advance,
Eldar.
More information about the Digitalmars-d-learn
mailing list