std::experi...lt_searcher(3)
π NAME π
okay bestie, welcome to the std::experi...lt_searcher(3) page from the C++ Standard Libary manual. We're talking about std::experimental::default_searcher,std::experimental::make_default_searcher β and the original NAME line literally repeats it: std::experimental::default_searcher,std::experimental::make_default_searcher. It's giving "two names, one search helper, zero chill." π
β¨ Synopsis β¨
Defined in header <experimental/functional>.
template< class ForwardIterator1, class BinaryPredicate = std::equal_to<> >
class default_searcher;
(library fundamentals TS)
A class suitable for use with std::experimental::search that delegates the search operation to the standard library's std::search. Obsessed: it's just handing the actual search off to std::search.
default_searcher is CopyConstructible and CopyAssignable. No cap. π«Ά
π Member functions π
πΈ std::experimental::default_searcher::default_searcher πΈ
default_searcher( ForwardIterator pat_first, ForwardIterator pat_last, BinaryPredicate pred = BinaryPredicate() );
Constructs a default_searcher by storing copies of pat_first, pat_last, and pred. It's literally copying the whole vibe into the searcher.
Parameters
pat_first,pat_lastβ a pair of iterators designating the string to be searched for.predβ a callable object used to determine equality.
Exceptions
Any exceptions thrown by the copy constructors of BinaryPredicate or ForwardIterator. So if those copy constructors throw, this constructor is not gonna pretend everything's fine. π
π std::experimental::default_searcher::operator() π
until C++17:
template< class ForwardIterator2 >
ForwardIterator2 operator()( ForwardIterator2 first, ForwardIterator2 last ) const;
since C++17:
template< class ForwardIterator2 >
std::pair<ForwardIterator2, ForwardIterator2>
operator()( ForwardIterator2 first, ForwardIterator2 last ) const;
The member function called by std::experimental::search to perform a search with this searcher. It's the actual "do the thing" button, iykyk. π₯
- Equivalent to
std::search(first, last, pat_first, pat_last, pred);. (until C++17) - Returns a pair of iterators
i,j, whereiisstd::search(first, last, pat_first, pat_last, pred)andjisstd::next(i, std::distance(pat_first, pat_last))unlessstd::searchreturnedlast(no match), in which casejequalslastas well. (until C++17)
(Yes bestie, the page puts until C++17 there again. I'm preserving the label exactly β don't come for me. π«Ά)
Parameters
first,lastβ a pair of iterators designating the string to be examined.
Return value
- until C++17: Iterator to the first position in
[first, last)where a subsequence that compares equal to[pat_first, pat_last)as defined bypredis located, or a copy oflastotherwise. - since C++17: 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 bypredis located, or a pair of copies oflastotherwise.
π§ Helper Functions π§
template< class ForwardIterator, class BinaryPredicate = std::equal_to<> >
default_searcher<ForwardIterator, BinaryPredicate>
make_default_searcher(
ForwardIterator pat_first,
ForwardIterator pat_last,
BinaryPredicate pred = BinaryPredicate());
(library fundamentals TS)
Helper function that constructs a std::experimental::default_searcher using template argument deduction. Equivalent to return default_searcher<ForwardIterator, BinaryPredicate>(pat_first, pat_last, pred);. Template argument deduction ate, fr fr. β¨
Parameters
pat_first,pat_lastβ a pair of iterators designating the string to be searched for.predβ a callable object used to determine equality.
Return value
A default_searcher constructed with the arguments pat_first, pat_last, 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_default_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
okay that's the whole page, bestie. This icon was served by http://cppreference.com, version/date 2024.06.10, and it's the std::experi...lt_searcher(3) manual page. periodt. πβ¨π
π¦ 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