std::default_searcher(3)
π std::default_searcher(3) β C++ Standard Libary bestie edition π
Okay so you opened the manual page for std::default_searcher(3) from the C++ Standard Libary (yes, thatβs the manual name, and weβre keeping it exactly like that, no cap). Weβre gonna make this searcher make sense, fr fr. Slay.
π NAME π
std::default_searcher - std::default_searcher
Thatβs literally the whole name section. Iconic. No notes.
πΈ SYNOPSIS πΈ
Defined in header <functional>.
template< class ForwardIt, class BinaryPredicate = std::equal_to<> >
class default_searcher;
(since C++17)
A class suitable for use with the Searcher overload of std::search that delegates the search operation to the pre-C++17 standard libraryβs std::search.
std::default_searcher is CopyConstructible and CopyAssignable.
π MEMBER FUNCTIONS π
π
std::default_searcher::default_searcher
default_searcher( ForwardIt pat_first,
ForwardIt pat_last,
BinaryPredicate pred = BinaryPredicate() );
(since C++17) (until C++20)
constexpr default_searcher( ForwardIt pat_first,
ForwardIt pat_last,
BinaryPredicate pred = BinaryPredicate() );
(since C++20)
Constructs a std::default_searcher by storing copies of pat_first, pat_last, and pred.
π PARAMETERS π
pat_first,pat_lastβ a pair of iterators designating the string to be searched forpredβ a callable object used to determine equality
π EXCEPTIONS π
Any exceptions thrown by the copy constructors of BinaryPredicate or ForwardIt.
β¨ std::default_searcher::operator() β¨
template< class ForwardIt2 >
std::pair<ForwardIt2, ForwardIt2>
operator()( ForwardIt2 first, ForwardIt2 last ) const;
(since C++17) (until C++20)
template< class ForwardIt2 >
constexpr std::pair<ForwardIt2, ForwardIt2>
operator()( ForwardIt2 first, ForwardIt2 last ) const;
(since C++20)
The member function called by the Searcher overload of std::search to perform a search with this searcher.
Returns a pair of iterators i, j, where i is std::search(first, last, pat_first, pat_last, pred) and j is std::next(i, std::distance(pat_first, pat_last)) unless std::search returned last (no match), in which case j equals last as well.
π PARAMETERS π
first,lastβ a pair of iterators designating the string to be examined
π RETURN VALUE π
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 a pair of copies of last otherwise.
π¦ EXAMPLE π¦
// Run this code
#include <algorithm>
#include <functional>
#include <iomanip>
#include <iostream>
#include <string_view>
int main()
{
constexpr std::string_view in =
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed "
"do eiusmod tempor incididunt ut labore et dolore magna aliqua";
const std::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';
else
std::cout << "The string " << std::quoted(needle) << " not found\n";
}
π OUTPUT π
The string "pisci" found at offset 43
π SEE ALSO π
searchβ searches for a range of elements (function template)boyer_moore_searcherβ Boyer-Moore search algorithm implementation(C++17)(class template)boyer_moore_horspool_searcherβ Boyer-Moore-Horspool search algorithm implementation(C++17)(class template)
Source/version/date tea β: http://cppreference.com, 2024.06.10, and this page is std::default_searcher(3). Byeee, go search something cute πβ¨
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms