std::experi...erator_tag,(3)
β¨ 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_tagcorresponds toInputIterator.forward_iterator_tagcorresponds toForwardIterator.bidirectional_iterator_tagcorresponds toBidirectionalIterator.random_access_iterator_tagcorresponds toRandomAccessIterator.output_iterator_tagcorresponds toOutputIteratorβ 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_tagoutput_iterator_tagforward_iterator_tagbidirectional_iterator_tag(class)random_access_iterator_tagcontiguous_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
- 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