8#ifndef INCLUDED_BSLSTL_DEFAULTSEARCHER
9#define INCLUDED_BSLSTL_DEFAULTSEARCHER
353#include <bslscm_version.h>
384template <
class FORWARD_ITR_NEEDLE,
386 typename bsl::iterator_traits<FORWARD_ITR_NEEDLE>::value_type> >
393 typedef typename bsl::iterator_traits<FORWARD_ITR_NEEDLE>::value_type
396 typedef typename bsl::iterator_traits<FORWARD_ITR_NEEDLE>::
400 FORWARD_ITR_NEEDLE d_needleFirst;
401 FORWARD_ITR_NEEDLE d_needleLast;
414 EQUAL
equal = EQUAL());
461 template<
class FORWARD_ITR_HAYSTACK>
463 FORWARD_ITR_HAYSTACK haystackFirst,
464 FORWARD_ITR_HAYSTACK haystackLast)
const;
491template <
class FORWARD_ITR_NEEDLE,
493 class FORWARD_ITR_HAYSTACK>
505 bsl::iterator_traits<FORWARD_ITR_NEEDLE>::value_type
510 bsl::iterator_traits<FORWARD_ITR_NEEDLE>::value_type
514 bsl::iterator_traits<FORWARD_ITR_HAYSTACK>::value_type
531 template <
class FORWARD_ITR_NEEDLE,
533 class FORWARD_ITR_HAYSTACK>
538 FORWARD_ITR_HAYSTACK>::value
540 FORWARD_ITR_HAYSTACK>
541 >::type
doSearch(
const FORWARD_ITR_HAYSTACK& haystackFirst,
542 const FORWARD_ITR_HAYSTACK& haystackLast,
543 const FORWARD_ITR_NEEDLE& needleFirst,
544 const FORWARD_ITR_NEEDLE& needleLast,
572 template <
class FORWARD_ITR_NEEDLE,
574 class FORWARD_ITR_HAYSTACK>
579 FORWARD_ITR_HAYSTACK>::value
581 FORWARD_ITR_HAYSTACK>
582 >::type
doSearch(
const FORWARD_ITR_HAYSTACK& haystackFirst,
583 const FORWARD_ITR_HAYSTACK& haystackLast,
584 const FORWARD_ITR_NEEDLE& needleFirst,
585 const FORWARD_ITR_NEEDLE& needleLast,
592#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_FUNCTORS
601template<
class ForwardIterator1,
602 class BinaryPredicate = equal_to<
603 typename bsl::iterator_traits<ForwardIterator1>::value_type> >
607 BloombergLP::bslstl::DefaultSearcher<ForwardIterator1,
608 BinaryPredicate> d_imp;
620 ForwardIterator1 pat_last,
621 BinaryPredicate pred = BinaryPredicate());
646 BloombergLP::bslmf::MovableRef<default_searcher>
667 template<
class ForwardIterator2>
670 ForwardIterator2 first,
671 ForwardIterator2 last)
const;
689template <
class FORWARD_ITR_NEEDLE,
692DefaultSearcher<FORWARD_ITR_NEEDLE,
695 FORWARD_ITR_NEEDLE needleLast,
697: d_needleFirst(needleFirst)
698, d_needleLast( needleLast)
701 BSLS_ASSERT(0 <= bsl::distance(needleFirst, needleLast));
705template <
class FORWARD_ITR_NEEDLE,
707template <
class FORWARD_ITR_HAYSTACK>
711 FORWARD_ITR_HAYSTACK haystackFirst,
712 FORWARD_ITR_HAYSTACK haystackLast)
const
715 typename bsl::iterator_traits<FORWARD_ITR_NEEDLE >::value_type,
716 typename bsl::iterator_traits<FORWARD_ITR_HAYSTACK>::value_type
719 return BloombergLP::bslstl::
720 DefaultSearcher_ImpUtil::doSearch<FORWARD_ITR_NEEDLE,
722 FORWARD_ITR_HAYSTACK>(
731template <
class FORWARD_ITR_NEEDLE,
class EQUAL>
736 return d_needleFirst;
739template <
class FORWARD_ITR_NEEDLE,
class EQUAL>
747template <
class FORWARD_ITR_NEEDLE,
class EQUAL>
759template <
class FORWARD_ITR_NEEDLE,
class EQUAL,
class FORWARD_ITR_HAYSTACK>
765 FORWARD_ITR_HAYSTACK>::value
768 const FORWARD_ITR_HAYSTACK& haystackFirst,
769 const FORWARD_ITR_HAYSTACK& haystackLast,
770 const FORWARD_ITR_NEEDLE& needleFirst,
771 const FORWARD_ITR_NEEDLE& needleLast,
774 BSLS_ASSERT(0 <= bsl::distance(haystackFirst, haystackLast));
776 for (FORWARD_ITR_HAYSTACK itrHaystackOuter = haystackFirst;
777 itrHaystackOuter != haystackLast;
778 ++itrHaystackOuter) {
780 FORWARD_ITR_HAYSTACK itrHaystackInner = itrHaystackOuter;
782 for (FORWARD_ITR_NEEDLE itrNeedle = needleFirst;
784 ++itrNeedle, ++itrHaystackInner) {
786 if (needleLast == itrNeedle) {
787 return std::make_pair(itrHaystackOuter,
791 if (haystackLast == itrHaystackInner) {
792 return std::make_pair(haystackLast,
796 if (equal(*itrHaystackInner, *itrNeedle)) {
806 return std::make_pair(haystackLast, haystackLast);
809template <
class FORWARD_ITR_NEEDLE,
class EQUAL,
class FORWARD_ITR_HAYSTACK>
815 FORWARD_ITR_HAYSTACK>::value
818 const FORWARD_ITR_HAYSTACK& haystackFirst,
819 const FORWARD_ITR_HAYSTACK& haystackLast,
820 const FORWARD_ITR_NEEDLE& needleFirst,
821 const FORWARD_ITR_NEEDLE& needleLast,
831 typedef typename bsl::iterator_traits<FORWARD_ITR_HAYSTACK>::
835 typedef typename bsl::iterator_traits<FORWARD_ITR_NEEDLE>::difference_type
838 const NeedleDifference needleLength = needleLast - needleFirst;
839 const HaystackDifference haystackLength = haystackLast - haystackFirst;
844 if (haystackLength < needleLength) {
845 return std::make_pair(haystackLast, haystackLast);
848 if (0 == needleLength || 0 == haystackLength) {
849 return std::make_pair(haystackFirst, haystackFirst);
852 for (FORWARD_ITR_HAYSTACK itr = haystackFirst;
853 itr < haystackLast - needleLength + 1; ++itr) {
855 FORWARD_ITR_HAYSTACK itrInner = itr;
856 FORWARD_ITR_NEEDLE needleItrInner = needleFirst;
857 NeedleDifference needleLengthInner = needleLength;
860 if (1 == needleLength) {
861 return std::make_pair(itr, itr + needleLength);
870 if (0 == std::memcmp( itrInner,
872 needleLengthInner)) {
873 return std::make_pair(itr, itr + needleLength);
878 return std::make_pair(haystackLast, haystackLast);
884#ifndef BSLS_LIBRARYFEATURES_HAS_CPP17_SEARCH_FUNCTORS
891template <
class ForwardIterator1,
892 class BinaryPredicate>
895default_searcher<ForwardIterator1,
896 BinaryPredicate>::default_searcher(ForwardIterator1 pat_first,
897 ForwardIterator1 pat_last,
898 BinaryPredicate pred)
899: d_imp(pat_first, pat_last, pred)
904template <
class ForwardIterator1,
905 class BinaryPredicate>
906template <
class ForwardIterator2>
909pair<ForwardIterator2,
911 BinaryPredicate>::operator()(
912 ForwardIterator2 first,
913 ForwardIterator2 last)
const
915 return d_imp(first, last);
Definition bslstl_defaultsearcher.h:604
default_searcher(const default_searcher &original)=default
default_searcher & operator=(BloombergLP::bslmf::MovableRef< default_searcher > rhs)=default
default_searcher(BloombergLP::bslmf::MovableRef< default_searcher > original)=default
default_searcher & operator=(const default_searcher &rhs)=default
BSLS_KEYWORD_CONSTEXPR pair< ForwardIterator2, ForwardIterator2 > operator()(ForwardIterator2 first, ForwardIterator2 last) const
Definition bslstl_defaultsearcher.h:911
~default_searcher()=default
Destroy this default_searcher object.
Definition bslstl_pair.h:1210
Definition bslstl_defaultsearcher.h:387
~DefaultSearcher()=default
Destroy this DefaultSearcher object.
DefaultSearcher & operator=(const DefaultSearcher &rhs)=default
FORWARD_ITR_NEEDLE needleFirst() const
Definition bslstl_defaultsearcher.h:733
bsl::pair< FORWARD_ITR_HAYSTACK, FORWARD_ITR_HAYSTACK > operator()(FORWARD_ITR_HAYSTACK haystackFirst, FORWARD_ITR_HAYSTACK haystackLast) const
Definition bslstl_defaultsearcher.h:710
FORWARD_ITR_NEEDLE needleLast() const
Definition bslstl_defaultsearcher.h:741
EQUAL equal() const
Definition bslstl_defaultsearcher.h:749
DefaultSearcher(DefaultSearcher &&original)=default
DefaultSearcher(const DefaultSearcher &original)=default
DefaultSearcher & operator=(DefaultSearcher &&rhs)=default
#define BSLMF_ASSERT(expr)
Definition bslmf_assert.h:229
#define BSLS_ASSERT(X)
Definition bsls_assert.h:1804
#define BSLS_IDENT(str)
Definition bsls_ident.h:195
#define BSLS_KEYWORD_CONSTEXPR
Definition bsls_keyword.h:588
Definition bdlb_printmethods.h:283
Definition bslstl_algorithm.h:82
Definition bslmf_enableif.h:525
Definition bslstl_equalto.h:311
Definition bslmf_ispointer.h:138
Definition bslmf_issame.h:146
Definition bslmf_isbitwiseequalitycomparable.h:499
Definition bslstl_defaultsearcher.h:494
@ value
Definition bslstl_defaultsearcher.h:498
Definition bslstl_defaultsearcher.h:528
static bsl::enable_if< DefaultSearcher_CanOptimize< FORWARD_ITR_NEEDLE, EQUAL, FORWARD_ITR_HAYSTACK >::value, bsl::pair< FORWARD_ITR_HAYSTACK, FORWARD_ITR_HAYSTACK > >::type doSearch(const FORWARD_ITR_HAYSTACK &haystackFirst, const FORWARD_ITR_HAYSTACK &haystackLast, const FORWARD_ITR_NEEDLE &needleFirst, const FORWARD_ITR_NEEDLE &needleLast, const EQUAL &equal)
Definition bslstl_defaultsearcher.h:767
static bsl::enable_if<!DefaultSearcher_CanOptimize< FORWARD_ITR_NEEDLE, EQUAL, FORWARD_ITR_HAYSTACK >::value, bsl::pair< FORWARD_ITR_HAYSTACK, FORWARD_ITR_HAYSTACK > >::type doSearch(const FORWARD_ITR_HAYSTACK &haystackFirst, const FORWARD_ITR_HAYSTACK &haystackLast, const FORWARD_ITR_NEEDLE &needleFirst, const FORWARD_ITR_NEEDLE &needleLast, const EQUAL &equal)