std::experi...ol_searcher,(3)

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

πŸ’… std::experi...ol_searcher,(3) πŸ’…

okay bestie, this is the C++ Standard Libary page for std::experimental::boyer_moore_horspool_searcher β€” the header literally renders as std::experi...ol_searcher,(3), and the manual name is folded right here instead of pasted as a line. It’s part of the library fundamentals TS. 🫢


🌸 NAME 🌸

std::experimental::boyer_moore_horspool_searcher, - std::experimental::boyer_moore_horspool_searcher,

Yup, that’s the NAME line with both copies and the trailing comma. No cap, we keep it exactly. πŸ’…

✨ Synopsis ✨

Defined in header <experimental/functional>.

template< class RandomIt1,
          class Hash = std::hash<typename std::iterator_traits<RandomIt1>::value_type>,
          class BinaryPredicate = std::equal_to<> >
class boyer_moore_horspool_searcher;

This is a searcher built for use with std::experimental::search, and it implements the Boyer-Moore-Horspool string searching algorithm. 🌈

boyer_moore_horspool_searcher is CopyConstructible and CopyAssignable.

RandomIt1 must meet the requirements of LegacyRandomAccessIterator.

Library fundamentals TS bit: this class is the TS flavor, so keep that std::experimental:: prefix close. 🧚

πŸ› οΈ Member functions πŸ› οΈ

😭 std::experimental::boyer_moore_horspool_searcher::boyer_moore_horspool_searcher

boyer_moore_horspool_searcher( RandomIt1 pat_first,
                               RandomIt1 pat_last,
                               Hash hf = Hash(),
                               BinaryPredicate pred = BinaryPredicate() );

This constructor builds a boyer_moore_horspool_searcher by storing copies of pat_first, pat_last, hf, and pred, and setting up any necessary internal data structures. πŸŽ€

The value type of RandomIt1 must be DefaultConstructible, CopyConstructible, and CopyAssignable.

For any two values A and B of the type std::iterator_traits<RandomIt1>::value_type, if pred(A, B) == true, then hf(A) == hf(B) shall be true. That’s the hash/equality promise, bestie β€” it has to hold. πŸ’–

Parameters

  • pat_first, pat_last β€” a pair of iterators designating the string to be searched for.
  • hf β€” a callable object used to hash the elements of the string.
  • pred β€” a callable object used to determine equality.

Exceptions

Any exceptions thrown by:

  • the copy constructor of RandomIt1;
  • the default constructor, copy constructor, or copy assignment operator of the value type of RandomIt1; or
  • the copy constructor or function call operator of BinaryPredicate or Hash.

May also throw std::bad_alloc if additional memory required for internal data structures cannot be allocated. 😭

πŸ”Ž std::experimental::boyer_moore_horspool_searcher::operator()

template< class RandomIt2 >
RandomIt2 operator()( RandomIt2 first, RandomIt2 last ) const;

(until C++17)

template< class RandomIt2 >
std::pair<RandomIt2,RandomIt2> operator()( RandomIt2 first, RandomIt2 last ) const;

(since C++17)

This is the member function that std::experimental::search calls to perform a search with this searcher. RandomIt2 must meet the requirements of LegacyRandomAccessIterator. πŸ¦‹

RandomIt1 and RandomIt2 must have the same value type.

Parameters

  • first, last β€” a pair of iterators designating the string to be examined.

Return value

Until C++17:

If the pattern [pat_first, pat_last) is empty, returns first.

Otherwise, returns an iterator to the first position in [first, last) where a subsequence that compares equal to [pat_first, pat_last) as defined by pred is located, or a copy of last otherwise.

Since C++17:

If the pattern [pat_first, pat_last) is empty, returns make_pair(first, first).

Otherwise, returns 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 pred is located, or make_pair(last, last) otherwise. ✨


🧚 Helper Functions 🧚

template< class RandomIt,
          class Hash = std::hash<typename std::iterator_traits<RandomIt>::value_type>,
          class BinaryPredicate = std::equal_to<> >
boyer_moore_horspool_searcher<RandomIt, Hash, BinaryPredicate>
    make_boyer_moore_horspool_searcher( RandomIt pat_first,
                                        RandomIt pat_last,
                                        Hash hf = Hash(),
                                        BinaryPredicate pred = BinaryPredicate() );

Helper function that constructs a std::experimental::boyer_moore_horspool_searcher using template argument deduction. Equivalent to:

return boyer_moore_horspool_searcher<RandomIt, Hash, BinaryPredicate>(pat_first, pat_last, hf, pred);
Library fundamentals TS bit again: this helper is the TS one too. πŸ’œ

Parameters

  • pat_first, pat_last β€” a pair of iterators designating the string to be searched for.
  • hf β€” a callable object used to hash the elements of the string.
  • pred β€” a callable object used to determine equality.

Return value

A boyer_moore_horspool_searcher constructed with the arguments pat_first, pat_last, hf, and pred. πŸŽ€


πŸ“ Example πŸ“

// Run this code

#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_horspool_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).

🏷️ Category 🏷️

  • Noindexed pages

Sign-off time, bestie: this page comes from http://cppreference.com, version/date 2024.06.10, and the footer title is std::experi...ol_searcher,(3). Slay. πŸ’…βœ¨

πŸ“¦ where this page comes from