Merge pull request #6796 from carun/master

canFind: added example to search for multiple needles in a hay stack.
merged-on-behalf-of: Sebastian Wilzbach <sebi.wilzbach@gmail.com>
This commit is contained in:
The Dlang Bot 2018-12-11 11:58:05 +01:00 committed by GitHub
commit d262d06a14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2557,6 +2557,17 @@ template canFind(alias pred="a == b")
assert( canFind!((string a, string b) => a.startsWith(b))(words, "bees"));
}
/// Search for mutliple items in an array of items (search for needles in an array of hay stacks)
@safe unittest
{
string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hay.canFind!(e => (e.canFind("111", "222"))));
}
@safe unittest
{
import std.algorithm.internal : rndstuff;