|
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Old binders and adaptors | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Defined in header <functional> | ||
template<class ForwardIt,class BinaryPredicate=std::equal_to<>> class default_searcher; | (since C++17) | |
A class suitable for use withSearcher overload ofstd::search that delegates the search operation to the pre-C++17 standard library'sstd::search.
std::default_searcher isCopyConstructible andCopyAssignable.
Contents |
default_searcher( ForwardIt pat_first, ForwardIt pat_last, | (since C++17) (constexpr since C++20) | |
Constructs astd::default_searcher by storing copies ofpat_first,pat_last, andpred.
| 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 ofBinaryPredicate orForwardIt.
template<class ForwardIt2> std::pair<ForwardIt2, ForwardIt2> | (since C++17) (constexpr since C++20) | |
The member function called by the Searcher overload ofstd::search to perform a search with this searcher.
Returns a pair of iteratorsi, j, wherei isstd::search(first, last, pat_first, pat_last, pred) andj isstd::next(i,std::distance(pat_first, pat_last)) unlessstd::search returnedlast (no match), in which casej equalslast as well.
| first, last | - | a pair of iterators designating the string to be examined |
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 bypred is located, or a pair of copies oflast otherwise.
#include <algorithm>#include <functional>#include <iomanip>#include <iostream>#include <string_view> int main(){constexprstd::string_view in="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed ""do eiusmod tempor incididunt ut labore et dolore magna aliqua"; conststd::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';elsestd::cout<<"The string "<<std::quoted(needle)<<" not found\n";}
Output:
The string "pisci" found at offset 43
| searches for the first occurrence of a range of elements (function template)[edit] | |
(C++17) | Boyer-Moore search algorithm implementation (class template)[edit] |
| Boyer-Moore-Horspool search algorithm implementation (class template)[edit] |