A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://en.cppreference.com/w/cpp/algorithm/../algorithm/../experimental/search.html below:

std::experimental::search - cppreference.com

template< class ForwardIterator, class Searcher >

ForwardIterator search( ForwardIterator first, ForwardIterator last,

                        const Searcher& searcher );
(library fundamentals TS)

Searches the sequence [firstlast) for the pattern specified in the constructor of searcher.

Effectively executes searcher(first, last).

(until C++17)

Effectively executes searcher(first, last).first.

(since C++17)

Searcher need not be CopyConstructible.

The standard library provides the following searchers:

[edit] Parameters [edit] Return value

Returns the result of searcher.operator(), that is, an iterator to the location at which the substring is found or a copy of last if it was not found.

[edit] Complexity

Depends on the searcher.

[edit] Example
#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';
    else
        std::cout << "The string " << needle << " not found\n";
}

Output:

The string pisci found at offset 43
[edit] See also searches for the first occurrence of a range of elements
(function template) [edit]

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4