From 1a6d95580f909d86a6762ec32754ae1db9da2caa Mon Sep 17 00:00:00 2001 From: q66 Date: Tue, 11 Aug 2015 01:32:24 +0100 Subject: [PATCH] add algorithm::find_one_of (finds the first occurence of any value in the second range in the first range, then returns the range) --- ostd/algorithm.hh | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/ostd/algorithm.hh b/ostd/algorithm.hh index 3ea5d86..ff73e20 100644 --- a/ostd/algorithm.hh +++ b/ostd/algorithm.hh @@ -292,6 +292,24 @@ R find_if_not(R range, P pred) { return range; } +template +R1 find_one_of(R1 range, R2 values, C compare) { + for (; !range.empty(); range.pop_front()) + for (R2 rv = values; !rv.empty(); rv.pop_front()) + if (compare(range.front(), rv.front())) + return range; + return range; +} + +template +R1 find_one_of(R1 range, R2 values) { + for (; !range.empty(); range.pop_front()) + for (R2 rv = values; !rv.empty(); rv.pop_front()) + if (range.front() == rv.front()) + return range; + return range; +} + template RangeSize count(R range, const T &v) { RangeSize ret = 0;