std::ranges...++,--,+=,-=(3)

πŸ“¦ version 2024.07.05, in nixpkgs unstable, opensuse-leap 16.0

πŸŽ€ NAME πŸŽ€

This is the std::ranges...++,--,+=,-=(3) page from the C++ Standard Libary manual β€” yes, bestie, that’s the manual name as printed in the header, typo and all, and we’re keeping it because details are sacred. It’s the cppreference C++ Standard Library page all about std::ranges::chunk_view::iterator::operator++,--,+=,-=. The original NAME section lists std::ranges::chunk_view::iterator::operator++,--,+=,-= twice, so here’s the second mention too: std::ranges::chunk_view::iterator::operator++,--,+=,-=. Double name, double slay, no skipping πŸ’…

✨ Synopsis ✨

Every single one of these is (since C++23) β€” C++23 girlies rise:

constexpr /*iterator*/& operator++();                   (1) (since C++23)
constexpr /*iterator*/ operator++( int );               (2) (since C++23)
constexpr /*iterator*/& operator--()                    (3) (since C++23)
    requires ranges::bidirectional_range<Base>;
constexpr /*iterator*/ operator--( int )                (4) (since C++23)
    requires ranges::bidirectional_range<Base>;
constexpr /*iterator*/& operator+=( difference_type x ) (5) (since C++23)
    requires ranges::random_access_range<Base>;
constexpr /*iterator*/& operator-=( difference_type x ) (6) (since C++23)
    requires ranges::random_access_range<Base>;

Advances or decrements the iterator.

Let current_, end_, and n_ be the underlying data members of chunk_view::iterator.

  1. Equivalent to:
missing_ = ranges::advance(current_, n_, end_);
return *this;

Before the invocation the expression current_ != end_ must be true, otherwise the behavior is undefined. 🚨

  1. Equivalent to: auto tmp = *this; ++*this; return tmp;.
  2. Equivalent to:
ranges::advance(current_, missing_ - n_);
missing_ = 0;
return *this;
  1. Equivalent to: auto tmp = *this; --*this; return tmp;.
  2. Equivalent to:
if (x > 0)
{
    ranges::advance(current_, n_ * (x - 1));
    missing_ = ranges::advance(current_, n_, end_);
}
else if (x < 0)
{
    ranges::advance(current_, n_ * x + missing_);
    missing_ = 0;
}
return *this;

If x is positive, then before the invocation the expression ranges::distance(current_, end_) > n_ * (x - 1) must be true (i.e., informally, the requested chunk should be "inside" the underlying sequence). If x is negative, this precondition is always met.

  1. Equivalent to: return *this += -x;.

🌸 Parameters 🌸

  • x β€” a position relative to current location πŸ“

πŸ’– Return value πŸ’–

  • 1,3,5,6) β€” *this
  • 2,4) β€” a copy of *this that was made before the change

πŸ¦‹ Example πŸ¦‹

This section is incomplete. Reason: no example. 😭

🌈 See also 🌈

  • operator+ performs iterator arithmetic
  • operator- (function) (C++23)

🏷️ Category: 🏷️

  • Todo no example

Signed off with all the love and C++23 sparkles: source/version http://cppreference.com, date 2024.06.10 β€” muah πŸ’‹βœ¨

πŸ“¦ where this page comes from