std::incrementable(3)
π NAME π
std::incrementable β bestie, it's literally std::incrementable β¨
π¦ Synopsis π¦
Okay so first things first, this whole thing lives in the header <iterator> π
template< class I >
concept incrementable =
std::regular<I> &&
std::weakly_incrementable<I> && (since C++20)
requires(I i) {
{ i++ } -> std::same_as<I>;
};
So what this concept actually does β no cap β is specify requirements on types that can be incremented with the pre- and post-increment operators π«Ά. Their increment operations have to be equality-preserving, and the type has to be std::equality_comparable. That's the vibe check π
.
And like, here's the glow-up: std::weakly_incrementable only supports single-pass algorithms π, but types that model std::incrementable can be used with multi-pass one-directional algorithms. She leveled up π.
β¨ Semantic requirements β¨
I models std::incrementable only if, given any two incrementable objects a and b of type I:
bool(a == b)impliesbool(a++ == b), andbool(a == b)impliesbool(((void)a++, a) == ++b).
Periodt π those are the rules.
πΈ Equality preservation πΈ
Expressions declared in requires expressions of the standard library concepts are required to be equality-preserving (except where stated otherwise). Not me reminding you again, but yeah π.
β See also β
weakly_incrementable(C++20) (concept) β specifies that a semiregular type can be incremented with pre- and post-increment operatorssame_as(C++20) (concept) β specifies that a type is the same as another type
okay that's the whole page bestie, go forth and increment responsibly π§π
signed, sealed, delivered with love π from http://cppreference.com, version/date 2024.06.10 β that's the std::incrementable(3) era, iykyk ππ₯
π¦ where this page comes from
- nixpkgs unstable: stdman 2024.07.05
- opensuse-leap 16.0: stdman 2024.07.05-bp160.1.9 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms