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

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

πŸŽ€ NAME πŸŽ€

std::ranges::adjacent_transform_view::iterator::operator++,--,+=,-= β€” like, the whole squad of increment/decrement/advance operators for std::ranges::adjacent_transform_view::iterator, all in one place. Yes, they all live here. It's giving "operator overload family reunion" and honestly? iconic. πŸ’…

Heads up bestie, this one's from the C++ Standard Libary manpages (section 3) β€” that's the C++ standard library docs, and no, I did not typo "Libary", that's literally how it's spelled up top. πŸ’–

✨ Synopsis ✨

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 n ) (5) (since C++23)
    requires ranges::random_access_range<Base>;
constexpr /*iterator*/& operator-=( difference_type n ) (6) (since C++23)
    requires ranges::random_access_range<Base>;

So what do these bad boys do? They increment or decrement the iterator. That's the whole vibe check. 🌸

Two names you gotta know, fr fr:

  • Let inner_ be the underlying iterator.
  • Let Base be the exposition-only member type.

And here's what each one is exactly equivalent to β€” no cap, this is the real mapping:

1) ++inner_; return *this;
2) auto tmp = *this; ++*this; return tmp;
3) --inner_; return *this;
4) auto tmp = *this; --*this; return tmp;
5) inner_ += n; return *this;
6) inner_ -= n; return *this;

Lowkey the cleanest little table of operator behaviour you'll ever see. πŸ¦‹


🌈 Parameters 🌈

  • n β€” position relative to current location. That's it, that's the parameter. 🫢

πŸ’– Return value πŸ’–

  • 1, 3, 5, 6) β€” *this. The iterator itself, coming right back atcha. ✨
  • 2, 4) β€” a copy of *this that was made before the change. So like, the post-increment/post-decrement versions hand you the old you. Main character energy: they remember who you were. 😭

πŸ™ˆ Example πŸ™ˆ

This section is incomplete.

Reason: no example.

Not me finding an empty example section 😭 bestie the docs said "figure it out yourself" and honestly? fair. πŸ’€

πŸ‘‘ See also πŸ‘‘

Category:

  • Todo no example

(Yeah, that's the whole see-also. We're all just vibing in the todo list together. πŸŽ€)


✨ that's the whole page, mwah ✨

Cute little sign-off: this was served fresh from http://cppreference.com, dated 2024.06.10, and it's page std::ranges...r++,--,+=,-=(3) of the C++ Standard Libary manpages. Go forth and increment responsibly, bestie πŸ§šπŸ’œ

πŸ“¦ where this page comes from