mirror of
https://github.com/dlang/phobos.git
synced 2025-05-12 07:08:48 +03:00
Merge pull request #3954 from quickfur/canfind_docs
Add example of how to use a custom predicate with canFind.
This commit is contained in:
commit
747135d6d6
1 changed files with 15 additions and 0 deletions
|
@ -2207,6 +2207,21 @@ template canFind(alias pred="a == b")
|
|||
assert(canFind([0, 1, 2, 3], [1, 3], [2, 4]) == 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Example using a custom predicate.
|
||||
* Note that the needle appears as the second argument of the predicate.
|
||||
*/
|
||||
@safe unittest
|
||||
{
|
||||
auto words = [
|
||||
"apple",
|
||||
"beeswax",
|
||||
"cardboard"
|
||||
];
|
||||
assert(!canFind(words, "bees"));
|
||||
assert( canFind!((string a, string b) => a.startsWith(b))(words, "bees"));
|
||||
}
|
||||
|
||||
@safe unittest
|
||||
{
|
||||
import std.algorithm.internal : rndstuff;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue