std::input_...put_iterator(3)

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

πŸ’… 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_readable and input_iterator) πŸ“
  • writing values to an iterator (see indirectly_writable and output_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