Add find_end algorithm and use it in string.

This commit is contained in:
Ion Gaztañaga
2021-01-02 17:03:15 +01:00
parent 150569375f
commit 2bd1a6f906
2 changed files with 50 additions and 23 deletions
@@ -118,6 +118,34 @@ InputIt find_if(InputIt first, InputIt last, UnaryPredicate p)
return last;
}
template<class ForwardIt1, class ForwardIt2, class BinaryPredicate>
ForwardIt1 find_end (ForwardIt1 first1, ForwardIt1 last1
,ForwardIt2 first2, ForwardIt2 last2
,BinaryPredicate p)
{
if (first2==last2)
return last1; // specified in C++11
ForwardIt1 ret = last1;
while (first1!=last1)
{
ForwardIt1 it1 = first1;
ForwardIt2 it2 = first2;
while ( p(*it1, *it2) ) {
++it1; ++it2;
if (it2==last2) {
ret=first1;
break;
}
if (it1==last1)
return ret;
}
++first1;
}
return ret;
}
template<class InputIt, class ForwardIt, class BinaryPredicate>
InputIt find_first_of(InputIt first1, InputIt last1, ForwardIt first2, ForwardIt last2, BinaryPredicate p)
{