| Defined in header
<functional> | ||
|---|---|---|
template< class ForwardIterator1, class BinaryPredicate = std::equal_to<> > class default_searcher; | (since C++17) |
A class suitable for use with Searcher overload of std::search that delegates the search operation to the pre-C++17 standard library's std::search.
default_searcher is CopyConstructible and CopyAssignable.
default_searcher( ForwardIterator pat_first,
ForwardIterator pat_last,
BinaryPredicate pred = BinaryPredicate());
|
Constructs a default_searcher by storing copies of pat_first, pat_last, and pred.
| pat_first, pat_last | - | a pair of iterators designating the string to be searched for |
| pred | - | a callable object used to determine equality |
Any exceptions thrown by the copy constructors of BinaryPredicate or ForwardIterator.
template< class ForwardIterator2 > ForwardIterator2 operator()( ForwardIterator2 first, ForwardIterator2 last ) const; | (until C++17) | |
template< class ForwardIterator2 >
std::pair<ForwardIterator2, ForwardIterator2>
operator()( ForwardIterator2 first, ForwardIterator2 last ) const;
| (since C++17) |
The member function called by the Searcher overload of std::search to perform a search with this searcher.
| Equivalent to | (until C++17) |
| Returns a pair of iterators | (until C++17) |
| first, last | - | a pair of iterators designating the string to be examined |
| Iterator to the first position in [first, last) where a subsequence that compares equal to [pat_first, pat_last) as defined by | (until C++17) |
| 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 | (since C++17) |
template< class ForwardIterator, class BinaryPredicate = std::equal_to<> >
default_searcher<ForwardIterator, BinaryPredicate> make_default_searcher(
ForwardIterator pat_first,
ForwardIterator pat_last,
BinaryPredicate pred = BinaryPredicate());
| (since C++17) |
Helper function that constructs a std::default_searcher using template argument deduction. Equivalent to return default_searcher<ForwardIterator, BinaryPredicate>(pat_first, pat_last, pred);
| pat_first, pat_last | - | a pair of iterators designating the string to be searched for |
| pred | - | a callable object used to determine equality |
A default_searcher constructed with the arguments pat_first, pat_last, pred.
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
int main()
{
std::string in = "Lorem ipsum dolor sit amet, consectetur adipiscing elit,"
" sed do eiusmod tempor incididunt ut labore et dolore magna aliqua";
std::string needle = "pisci";
auto it = std::search(in.begin(), in.end(),
std::make_default_searcher(
needle.begin(), needle.end()));
if(it != in.end())
std::cout << "The string " << needle << " found at offset "
<< it - in.begin() << '\n';
else
std::cout << "The string " << needle << " not found\n";
}Output:
The string pisci found at offset 43
| searches for a range of elements (function template) |
© cppreference.com
Licensed under the Creative Commons Attribution-ShareAlike Unported License v3.0.
http://en.cppreference.com/w/cpp/utility/functional/default_searcher