From 2bd1a6f90697e31368734d242f06a7d41d498654 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ion=20Gazta=C3=B1aga?= Date: Sat, 2 Jan 2021 17:03:15 +0100 Subject: [PATCH] Add find_end algorithm and use it in string. --- include/boost/container/detail/algorithm.hpp | 28 ++++++++++++ include/boost/container/string.hpp | 45 ++++++++++---------- 2 files changed, 50 insertions(+), 23 deletions(-) diff --git a/include/boost/container/detail/algorithm.hpp b/include/boost/container/detail/algorithm.hpp index 1184422..ce5582b 100644 --- a/include/boost/container/detail/algorithm.hpp +++ b/include/boost/container/detail/algorithm.hpp @@ -118,6 +118,34 @@ InputIt find_if(InputIt first, InputIt last, UnaryPredicate p) return last; } +template + 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 InputIt find_first_of(InputIt first1, InputIt last1, ForwardIt first2, ForwardIt last2, BinaryPredicate p) { diff --git a/include/boost/container/string.hpp b/include/boost/container/string.hpp index 60ba890..2adb0eb 100644 --- a/include/boost/container/string.hpp +++ b/include/boost/container/string.hpp @@ -2333,7 +2333,7 @@ class basic_string template