Movatterモバイル変換


[0]ホーム

URL:


cppreference.com
Namespaces
Variants
    Actions

      std::common_iterator<I,S>::operator++

      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)
       
       
      constexpr common_iterator& operator++();
      (1)(since C++20)
      constexpr decltype(auto) operator++(int);
      (2)(since C++20)
      Helper types
      class/*postfix_proxy*/{

         std::iter_value_t<I> keep_;
         constexpr postfix_proxy(std::iter_reference_t<I>&& x)
             : keep_(std::forward<std::iter_reference_t<I>>(x)){}
      public:
         constexprconststd::iter_value_t<I>& operator*()constnoexcept{
             return keep_;
         }

      };
      (3)(exposition only*)

      Increments the underlying iterator.

      The behavior is undefined if the underlyingstd::variant member objectvar does not hold an object of typeI, i.e.std::holds_alternative<I>(var) is equal tofalse.

      Letit denote the iterator of typeI held byvar, that isstd::get<I>(var).

      1) Pre-increments by one. Equivalent to++it;return*this;.
      2) Post-increments by one:
      • Equivalent to:auto tmp=*this;++*this;return tmp;, ifI modelsforward_iterator.
      • Equivalent to:return it++;, if the variable definitionauto&& ref=*it++; is well-formed, or either
      isfalse.
      • Equivalent to:postfix_proxy p(**this);++*this;return p; otherwise, wherepostfix_proxy is an exposition only helper type(3).

      Contents

      [edit]Parameters

      (none)

      [edit]Return value

      1)*this
      2) A copy of*this that was made before the change, or a result of post-increment of the underlying iterator, or a proxy keeping the value of the current element, as described above.

      [edit]Example

      Run this code
      #include <algorithm>#include <initializer_list>#include <iostream>#include <iterator> int main(){constauto il={1,2,3,4,5,6}; using CI=std::common_iterator<std::counted_iterator<std::initializer_list<int>::iterator>,std::default_sentinel_t>;     CI first{std::counted_iterator{std::begin(il),std::ssize(il)-2}}; for(; first!=std::default_sentinel;++first)std::cout<<*first<<' ';std::cout<<'\n';}

      Output:

      1 2 3 4

      [edit]Defect reports

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

      DRApplied toBehavior as publishedCorrect behavior
      P2259R1C++20post increment might discard its result in more situationsa proxy class is used to keep the result
      LWG 3546C++20initialization of the proxy object was sometimes ill-formedsituation and definition adjusted
      LWG 3574C++20variant was fully constexpr (P2231R1) butcommon_iterator was notalso made constexpr
      LWG 3595C++20functions of the proxy type lacked constexpr and noexceptadded

      [edit]See also

      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_arith&oldid=159811"

      [8]ページ先頭

      ©2009-2026 Movatter.jp