Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      operator==(std::common_iterator)

      From cppreference.com
      <cpp‎ |iterator‎ |common iterator
       
       
      Iterator library
      Iterator concepts
      Iterator primitives
      Algorithm concepts and utilities
      Indirect callable concepts
      Common algorithm requirements
      (C++20)
      (C++20)
      (C++20)
      Utilities
      (C++20)
      Iterator adaptors
      Range access
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++11)(C++14)
      (C++14)(C++14)  
      (C++17)(C++20)
      (C++17)
      (C++17)
       
       
      template<class I2,std::sentinel_for<I> S2>

          requiresstd::sentinel_for<S, I2>
      friendconstexprbool operator==(const common_iterator& x,

                                       conststd::common_iterator<I2, S2>& y);
      (1)(since C++20)
      template<class I2,std::sentinel_for<I> S2>

          requiresstd::sentinel_for<S, I2>&&std::equality_comparable_with<I, I2>
      friendconstexprbool operator==(const common_iterator& x,

                                       conststd::common_iterator<I2, S2>& y);
      (2)(since C++20)

      Compares the iterators and/or sentinels held by underlyingstd::variant member objectsvar. Two incomparable iterators or two sentinels are considered equal.

      The behavior is undefined if eitherx ory is in an invalid state, i.e.x.var.valueless_by_exception()|| y.var.valueless_by_exception() is equal totrue.

      Leti bex.var.index() andj bey.var.index().

      1) Ifi== j (i.e. bothx andy hold iterators or both hold sentinels), returnstrue, otherwise returnsstd::get<i>(x.var)== std::get<j>(y.var).
      2) Ifi==1&& j==1 (i.e. bothx andy hold sentinels), returnstrue, otherwise returnsstd::get<i>(x.var)== std::get<j>(y.var).

      The!= operator issynthesized fromoperator==.

      These function templates are not visible to ordinaryunqualified orqualified lookup, and can only be found byargument-dependent lookup when std::common_iterator<I> is an associated class of the arguments.

      Contents

      [edit]Parameters

      x, y - iterator adaptors to compare

      [edit]Return value

      true if underlying iterators and/or sentinels are equal.

      [edit]Example

      Run this code
      #include <cassert>#include <iterator> int main(){int a[]{0,1,2,3}; using CI=std::common_iterator<std::counted_iterator<int*>,std::default_sentinel_t>;     CI i1{std::counted_iterator{a+0,2}};    CI i2{std::counted_iterator{a+1,2}};    CI i3{std::counted_iterator{a+0,3}};    CI i4{std::counted_iterator{a+0,0}};    CI s1{std::default_sentinel};    CI s2{std::default_sentinel}; assert((i1== i2)==true);assert((i1== i3)==false);assert((i2== i3)==false);assert((s1== s2)==true);assert((i1== s1)==false);assert((i4== s1)==true);}

      [edit]Defect reports

      The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

      DRApplied toBehavior as publishedCorrect behavior
      LWG 3574C++20variant was fully constexpr (P2231R1) butcommon_iterator was notalso made constexpr

      [edit]See also

      (C++20)
      computes the distance between two iterator adaptors
      (function template)[edit]
      Retrieved from "https://en.cppreference.com/mwiki/index.php?title=cpp/iterator/common_iterator/operator_cmp&oldid=159362"

      [8]ページ先頭

      ©2009-2025 Movatter.jp