std::experi...erator_tag,(3)

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

✨ NAME ✨

std::experimental::ranges::input_iterator_tag β€” the whole little tag family, bestie πŸ’… (the man page title gets cut off but trust, it's the iterator tags from the C++ Standard Library and they're all here)


🌸 Synopsis 🌸

okay so first, the squad lineup β€” these three are the ones the synopsis shouts out:

std::experimental::ranges::forward_iterator_tag,
std::experimental::ranges::bidirectional_iterator_tag,
std::experimental::ranges::random_access_iterator_tag

and they're all defined in header <experimental/ranges/iterator> πŸŽ€

here's the actual structs, verbatim, no edits, i promise:

struct input_iterator_tag {};
struct output_iterator_tag {};
struct forward_iterator_tag : public input_iterator_tag {};
struct bidirectional_iterator_tag : public forward_iterator_tag {};
struct random_access_iterator_tag : public bidirectional_iterator_tag {};

so what are these? they define the category of an iterator πŸ¦‹. each tag is an empty type, and each one corresponds to one of the five iterator categories:

  • input_iterator_tag corresponds to InputIterator.
  • forward_iterator_tag corresponds to ForwardIterator.
  • bidirectional_iterator_tag corresponds to BidirectionalIterator.
  • random_access_iterator_tag corresponds to RandomAccessIterator.
  • output_iterator_tag corresponds to OutputIterator β€” no cap, it's not used and provided solely for backward compatiblity (yes that's how it's spelled in the source, leave her alone 😭).

lowkey the whole point: iterator category tags carry information that can be used to select the most efficient algorithms for the specific requirement set that is implied by the category. iconic behaviour honestly. BUT β€” and this is the plot twist β€” concept-based overloading is preferred ✨.

one more rule, and it's a big one πŸ‘‘: for every InputIterator type I, ranges::iterator_category_t<I> must be defined to be an alias for the most specific category tag that describes the iterator's behavior. periodt.


πŸŽ€ Example πŸŽ€

This section is incomplete Reason: no example

πŸ’€ not the empty example section. it's giving "trust me bro". moving on.


🌈 See also 🌈

  • input_iterator_tag
  • output_iterator_tag
  • forward_iterator_tag
  • bidirectional_iterator_tag (class)
  • random_access_iterator_tag
  • contiguous_iterator_tag (C++20)

…all of those are empty class types used to indicate iterator categories 🫢

and also:

  • iterator_traits β€” compatibility traits class that collects an iterator's associated types (alias template) ⭐

πŸ“ Category πŸ“

  • Todo no example πŸ™ˆ

ngl the vibe check here is: empty structs, huge consequences. don't sleep on them πŸ’œ

later bestie!! this page came from http://cppreference.com, version 2024.06.10 β€” slay, go read more, ily πŸ’–βœ¨

πŸ“¦ where this page comes from