Why do the same work about 'IndexOfAny' and 'indexOf' function?

ketmar via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Fri Jan 9 05:01:36 PST 2015


On Fri, 09 Jan 2015 12:46:53 +0000
FrankLike via Digitalmars-d-learn <digitalmars-d-learn at puremagic.com>
wrote:

> The code is the best,and it's better than indexOfAny in C#:
> 
> import std.algorithm, std.stdio;
> void main ()
> {
>      auto places = [ "home", "office", "sea","plane"];
>      auto strWhere = "He is in the sea.";
>      auto where = places.canFind!(a => strWhere.canFind(a));
>      writeln("Result is  ",where);
> }
this does unnecessary upvalue access (`strWhere`). try to avoid such
stuff whenever it is possible.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 181 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20150109/fbad4bc9/attachment-0001.sig>


More information about the Digitalmars-d-learn mailing list