std::input_iterator(3)

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

πŸ’… std::input_iterator(3) πŸ’…

okay bestie, welcome to the std::input_iterator(3) page from the C++ Standard Libary manual β€” yes, that's the manual name exactly, and we're keeping it πŸ’–. This is the whole thing, no cap, no skipped details.


🌸 NAME 🌸

std::input_iterator - std::input_iterator

πŸ¦‹ Synopsis πŸ¦‹

okay so it's Defined in header <iterator>, and it's tagged (since C++20) ✨. Here's the synopsis exactly as the page gives it, version marker and all:

          Defined in header <iterator>
          template< class I >

              concept input_iterator =
                  std::input_or_output_iterator<I> &&
                  std::indirectly_readable<I> &&
       (since C++20)
                  requires { typename /*ITER_CONCEPT*/<I>; } &&

                  std::derived_from</*ITER_CONCEPT*/<I>,
          std::input_iterator_tag>;

So the input_iterator concept is a refinement of input_or_output_iterator β€” it adds the requirement that the referenced values can be read (via indirectly_readable) and the requirement that the iterator concept tag be present. slay πŸ’…

πŸ’‘ Notes πŸ’‘

important note, bestie: Unlike the LegacyInputIterator requirements, the input_iterator concept does not require equality_comparable, since input iterators are typically compared with sentinels. iykyk ✨

🌈 Example 🌈

A minimum input iterator. iconic πŸ’–

#include <cstddef>
#include <iterator>

struct SimpleInputIterator
{
    using difference_type = std::ptrdiff_t;
    using value_type = int;

    int operator*() const;

    SimpleInputIterator& operator++();
    void operator++(int) { ++*this; }
};

static_assert(std::input_iterator<SimpleInputIterator>);

πŸ‘€ See also πŸ‘€

  • input_or_output_iterator β€” specifies that objects of a type can be incremented and dereferenced (concept) (C++20) πŸ¦‹
  • forward_iterator β€” specifies that an input_iterator is a forward iterator, supporting equality comparison and multi-pass (concept) (C++20) πŸ”₯

cute sign-off time: this page is from http://cppreference.com, version/date 2024.06.10, and it's the std::input_iterator(3) page β€” mwah, bestie πŸ’‹πŸ’–

πŸ“¦ where this page comes from