std::input_...put_iterator(3)
π NAME π
std::input_or_output_iterator β ok so bestie, this is literally THE concept that every iterator type has to slay π
β¨ SYNOPSIS β¨
So it lives in the header <iterator>, and it's giving this whole template vibe:
template< class I >
concept input_or_output_iterator =
requires(I i) { (since C++20)
{ *i } -> /*can-reference*/;
} &&
std::weakly_incrementable<I>;
The input_or_output_iterator concept is the blueprint, the foundation, the main character of the whole iterator concept taxonomy π«Ά β like, every single iterator type satisfies the input_or_output_iterator requirements. No cap.
And the exposition-only concept /*can-reference*/? It's satisfied if and only if the type is referenceable (in particular, not void) π β yes, void is literally not invited to this party.
This section is incomplete β Reason: Is *i required to be equality-preserving? (bestie we simply do not know yet π)
π¦ NOTES π¦
So like, input_or_output_iterator itself only specifies the operations for dereferencing and incrementing an iterator. That's it. That's the whole vibe check. Most algorithms are gonna want more, for example:
- comparing iterators with sentinels (see
sentinel_for) π - reading values from an iterator (see
indirectly_readableandinput_iterator) π - writing values to an iterator (see
indirectly_writableandoutput_iterator) βοΈ - a richer set of iterator movements (see
forward_iterator,bidirectional_iterator,random_access_iterator) πββοΈπ¨
And here's the iconic part: unlike the LegacyIterator requirements, the input_or_output_iterator concept does not require copyability. Periodt. π
πΈ EXAMPLE πΈ
A minimum iterator β literally the bare minimum and she still ate:
#include <cstddef>
#include <iterator>
struct SimpleIterator
{
using difference_type = std::ptrdiff_t;
int operator*();
SimpleIterator& operator++();
void operator++(int) { ++*this; }
};
static_assert(std::input_or_output_iterator<SimpleIterator>);
π CATEGORY π
- Todo with reason β¨
π§ ok that's the whole page bestie, go forth and increment π
Sign-off vibes: this lil masterpiece lives at http://cppreference.com, dated 2024.06.10, and the header up top said std::input_...put_iterator(3) (yes the ellipsis is doing its own thing, iconic honestly) πβ¨
π¦ 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