Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::experimental::ranges::search

      From cppreference.com
      <cpp‎ |experimental‎ |ranges
       
       
       
       
      Algorithms library
      Non-modifying sequence operations
      search
                                    
      Modifying sequence operations
                                    
      Partitioning operations
      Sorting operations
      Binary search operations
      Set operations (on sorted ranges)
                                    
      Heap operations
      Minimum/maximum operations
      Permutations
       
      template< ForwardIterator I1, Sentinel<I1> S1,

                ForwardIterator I2, Sentinel<I2> S2,class Pred=ranges::equal_to<>,
               class Proj1=ranges::identity,class Proj2=ranges::identity>
          requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>
      I1 search( I1 first1, S1 last1, I2 first2, S2 last2,

                 Pred pred= Pred{}, Proj1 proj1= Proj1{}, Proj2 proj2= Proj2{});
      (1)(ranges TS)
      template< ForwardRange R1, ForwardRange R2,class Pred=ranges::equal_to<>,

               class Proj1=ranges::identity,class Proj2=ranges::identity>
          requires IndirectlyComparable<ranges::iterator_t<R1>,ranges::iterator_t<R2>,
                                        Pred, Proj1, Proj2>
      ranges::safe_iterator_t<R1> search( R1&& r1, R2&& r2, Pred pred= Pred{},

                                          Proj1 proj1= Proj1{}, Proj2 proj2= Proj2{});
      (2)(ranges TS)
      1) Searches for the first occurrence of the sequence of elements[first2last2) in the range[first1last1). Elements are compared usingpred after being projected withproj2 andproj1, respectively.
      2) Same as(1), but usesr1 as the first source range andr2 as the second source range, as if usingranges::begin(r1) asfirst1,ranges::end(r1) aslast1,ranges::begin(r2) asfirst2, andranges::end(r2) aslast2.

      Notwithstanding the declarations depicted above, the actual number and order of template parameters for algorithm declarations is unspecified. Thus, if explicit template arguments are used when calling an algorithm, the program is probably non-portable.

      Contents

      [edit]Parameters

      first1, last1 - the range of elements to examine
      r1 - the range of elements to examine
      first2, last2 - the range of elements to search for
      r2 - the range of elements to search for
      pred - predicate to apply to the projected elements
      proj1 - projection to apply to the elements in the first range
      proj2 - projection to apply to the elements in the second range

      [edit]Return value

      An iterator to the beginning of first occurrence of the sequence[first2last2) in the range[first1last1). If[first2last2) is empty,first1 is returned. If no such occurrence is found, an iterator that compares equal tolast1 is returned.

      [edit]Complexity

      At mostS * N applications of the predicate and each projection, whereS= last2- first2 andN= last1- first1.

      [edit]Possible implementation

      template<ForwardIterator I1, Sentinel<I1> S1,         ForwardIterator I2, Sentinel<I2> S2,class Pred=ranges::equal_to<>,class Proj1=ranges::identity,class Proj2=ranges::identity>    requires IndirectlyComparable<I1, I2, Pred, Proj1, Proj2>I1 search(I1 first1, S1 last1, I2 first2, S2 last2,          Pred pred= Pred{}, Proj1 proj1= Proj1{}, Proj2 proj2= Proj2{}){for(;;++first1){        I1 it= first1;for(I2 it2= first2;;(void)++it,(void)++it2){if(it2== last2)return first1;if(it== last1)return it;if(!ranges::invoke(pred,ranges::invoke(proj1,*it),ranges::invoke(proj2,*it2)))break;}}}

      [edit]Example

      This section is incomplete
      Reason: no example

      [edit]See also

      searches for the first occurrence of a range of elements
      (function template)[edit]
      finds the last sequence of elements in a certain range
      (function template)[edit]
      returnstrue if one set is a subset of another
      (function template)[edit]
      determines if two sets of elements are the same
      (function template)[edit]
      finds the first element satisfying specific criteria
      (function template)[edit]
      returnstrue if one range is lexicographically less than another
      (function template)[edit]
      finds the first position where two ranges differ
      (function template)[edit]
      searches for a number consecutive copies of an element in a range
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/experimental/ranges/algorithm/search&oldid=155287"

      [8]ページ先頭

      ©2009-2026 Movatter.jp