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

Increments the underlying iterator.

# Declarations

constexpr common_iterator& operator++();

(since C++20)

constexpr decltype(auto) operator++( int );

(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:
constexpr const std::iter_value_t<I>& operator*() const noexcept {
return keep_;
}
};

(exposition only*)

# Example

#include <algorithm>
#include <initializer_list>
#include <iostream>
#include <iterator>
 
int main()
{
    const auto 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';
}

# Defect reports

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) but common_iterator was notalso made constexpr
LWG 3595C++20functions of the proxy type lacked constexpr and noexceptadded

# See also