std::experimental::search(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸ’– std::experimental::search(3) πŸ’–

okay so bestie, this is std::experimental::search(3) from the C++ Standard Libary manual, and it is lowkey iconic for finding patterns with searchers. periodt ✨

πŸ’– NAME πŸ’–

std::experimental::search β€” std::experimental::search

(the name section is literally giving "same name, same energy" and we respect it πŸ’…)

πŸ¦‹ Synopsis πŸ¦‹

Defined in header <experimental/algorithm>.

template< class ForwardIterator, class Searcher >

ForwardIterator search( ForwardIterator first,             (library
fundamentals TS)
ForwardIterator last,

                        const Searcher& searcher );

Searches the sequence [first, last) for the pattern specified in the constructor of searcher.

  • until C++17: effectively executes searcher(first, last).
  • since C++17: effectively executes searcher(first, last).first.

Searcher need not be CopyConstructible. iconic behavior, no cap πŸ’…

The standard library provides the following searchers:

  • default_searcher β€” standard C++ library search algorithm implementation (class template)
  • boyer_moore_searcher β€” Boyer-Moore search algorithm implementation (class template)
  • boyer_moore_horspool_searcher β€” Boyer-Moore-Horspool search algorithm implementation (class template)

🧚 Parameters 🧚

This section is incomplete 😭

πŸ‘‘ 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.

πŸ”₯ Complexity πŸ”₯

Depends on the searcher.

🌸 Example 🌸

Run this code, bestie:

        #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

🫢 See also 🫢

  • search β€” searches for a range of elements (function template)

🌈 Categories 🌈

  • Noindexed pages
  • Todo without reason

Source/version and date: cppreference.com, 2024.06.10. Bye bestie, go find your pattern and slay πŸ’…βœ¨πŸ¦‹

πŸ“¦ where this page comes from