View source code
							
							
						
								Display the source code in std/algorithm/searching.d from which this
								page was generated on github.
							
						
							Report a bug
							
						
								If you spot a problem with this page, click here to create a
								Bugzilla issue.
							
						
							
								Improve this page
							
							
					
								Quickly fork, edit online, and submit a pull request for this page.
								Requires a signed-in GitHub account. This works well for small changes.
								If you'd like to make larger changes you may want to consider using
								local clone.
							
						Template std.algorithm.searching.canFind
Convenience function. Like find, but only returns whether or not the search was successful.
						
				template canFind(alias pred)
				;
						
					
				For more information about pred see find.
Contained Functions
| Name | Description | 
|---|---|
| canFind | Returns trueif and only ifpred(e)is true for any valueein the
    input rangerange.
    Performs (at most) Ο(haystack) evaluations ofpred. | 
| canFind | Returns trueif and only ifneedlecan be found in    range. Performs Ο(haystack) evaluations ofpred. | 
| canFind | Returns the 1-based index of the first needle found in haystack. If no
    needle is found, then0is returned. | 
See Also
among for checking a value against multiple arguments.
Example
const arr = [0, 1, 2, 3];
assert(canFind(arr, 2));
assert(!canFind(arr, 4));
// find one of several needles
assert(arrExample
Example using a custom predicate. Note that the needle appears as the second argument of the predicate.
auto words = [
    "apple",
    "beeswax",
    "cardboard"
];
assert(!canFind(words, "bees"));
assert( canFind!((string elem, string needle) => elemExample
Search for multiple items in an array of items (search for needles in an array of haystacks)
string s1 = "aaa111aaa";
string s2 = "aaa222aaa";
string s3 = "aaa333aaa";
string s4 = "aaa444aaa";
const hay = [s1, s2, s3, s4];
assert(hayAuthors
License
					Copyright © 1999-2024 by the D Language Foundation | Page generated by ddox.