constexpr common_iterator& operator++(); | (1) | (since C++20) |
constexpr decltype(auto) operator++(int); | (2) | (since C++20) |
Helper types | | |
| (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 models
forward_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, where
postfix_proxy is an exposition only helper type(3).
[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
[edit]Defect reports
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
| DR | Applied to | Behavior as published | Correct behavior |
|---|
| P2259R1 | C++20 | post increment might discard its result in more situations | a proxy class is used to keep the result |
| LWG 3546 | C++20 | initialization of the proxy object was sometimes ill-formed | situation and definition adjusted |
| LWG 3574 | C++20 | variant was fully constexpr (P2231R1) butcommon_iterator was not | also made constexpr |
| LWG 3595 | C++20 | functions of the proxy type lacked constexpr and noexcept | added |
[edit]See also
| computes the distance between two iterator adaptors (function template)[edit] |