| Technical Specification | ||||
| Filesystem library(filesystem TS) | ||||
| Library fundamentals(library fundamentals TS) | ||||
| Library fundamentals 2(library fundamentals TS v2) | ||||
| Library fundamentals 3(library fundamentals TS v3) | ||||
| Extensions for parallelism(parallelism TS) | ||||
| Extensions for parallelism 2(parallelism TS v2) | ||||
| Extensions for concurrency(concurrency TS) | ||||
| Extensions for concurrency 2(concurrency TS v2) | ||||
| Concepts(concepts TS) | ||||
| Ranges(ranges TS) | ||||
| Reflection(reflection TS) | ||||
| Mathematical special functions(special functions TR) | ||||
| Experimental Non-TS | ||||
| Pattern Matching | ||||
| Linear Algebra | ||||
| std::execution | ||||
| Contracts | ||||
| 2D Graphics |
experimental::search | ||||
| Type-erased and polymorphic allocators | ||||
| Variable templates for type traits |
Defined in header <experimental/algorithm> | ||
template<class ForwardIterator,class Searcher> ForwardIterator search( ForwardIterator first, ForwardIterator last, | (library fundamentals TS) | |
Searches the sequence[first, last) for the pattern specified in the constructor ofsearcher.
Effectively executessearcher(first, last). | (until C++17) |
Effectively executessearcher(first, last).first. | (since C++17) |
Searcher need not beCopyConstructible.
The standard library provides the following searchers:
| standard C++ library search algorithm implementation (class template) | |
| Boyer-Moore search algorithm implementation (class template) | |
| Boyer-Moore-Horspool search algorithm implementation (class template) |
Contents |
| |||
Returns the result ofsearcher.operator(), that is, an iterator to the location at which the substring is found or a copy oflast if it was not found.
Depends on the searcher.
#include <experimental/algorithm>#include <experimental/functional>#include <iostream>#include <string> 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::experimental::search(in.begin(), in.end(),std::experimental::make_boyer_moore_searcher( needle.begin(), needle.end()));if(it!= in.end())std::cout<<"The string "<< needle<<" found at offset "<< it- in.begin()<<'\n';elsestd::cout<<"The string "<< 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] |