std::default_searcher
Min standard notice:
Header: <functional>
A class suitable for use with overload of std::search that delegates the search operation to the pre-C++17 standard library’s std::search.
# Declarations
template< class ForwardIt, class BinaryPredicate = std::equal_to<> >
class default_searcher;
(since C++17)
# Parameters
pat_first, pat_last: a pair of iterators designating the string to be searched forpred: a callable object used to determine equality
# Return value
A pair of iterators to the first and one past last positions in [first,last) where a subsequence that compares equal to [pat_first,pat_last) as defined by pred is located, or a pair of copies of last otherwise.
# Example
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string_view>
int main()
{
constexpr std::string_view in =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
"do eiusmod tempor incididunt ut labore et dolore magna aliqua";
const std::string_view needle{"pisci"};
auto it = std::search(in.begin(), in.end(),
std::default_searcher(
needle.begin(), needle.end()));
if (it != in.end())
std::cout << "The string " << std::quoted(needle) << " found at offset "
<< it - in.begin() << '\n';
else
std::cout << "The string " << std::quoted(needle) << " not found\n";
}