View source code Display the source code in std/algorithm/searching.d from which this page was generated on github. 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. Page wiki View or edit the community-maintained wiki page associated with this page.

Function std.algorithm.searching.findAmong

Searches the given range for an element that matches one of the given choices.

Advances seq by calling seq.popFront until either find!(pred)(choices, seq.front) is true, or seq becomes empty. Performs Ο(seq.length * choices.length) evaluations of pred.

Prototype

Range1 findAmong(alias pred, Range1, Range2)(
  Range1 seq,
  Range2 choices
)
if (isInputRange!Range1 && isForwardRange!Range2);

Parameters

NameDescription
pred The predicate to use for determining a match.
seq The input range to search.
choices A forward range of possible choices.

Returns

seq advanced to the first matching element, or until empty if there are no matching elements.

See Also

STL's find_first_of

Example

int[] a = [ -1, 0, 1, 2, 3, 4, 5 ];
int[] b = [ 3, 1, 2 ];
assert(findAmong(a, b) == a[2 .. $]);

Authors

Andrei Alexandrescu

License

Boost License 1.0.

Comments