std::experi...or_category(3)
π NAME π
std::experimental::ranges::iterator_category β ok so this whole page is about that, bestie, it's std::experimental::ranges::iterator_category fr fr π
(this lives in the C++ Standard Libary manual, yes that's the manual's name, no I'm not fixing the spelling, it's iconic π)
β¨ Synopsis β¨
It's defined in the header <experimental/ranges/iterator>, periodt:
template< class I > (1)
struct iterator_category {};
template< class T > (2)
struct iterator_category<T*>;
template< class T > (3)
struct iterator_category<const T> : iterator_category<T> {};
template< class T >
requires requires { typename T::iterator_category; } (4)
struct iterator_category<T>;
So what does it even do π β it computes the iterator category of the class I, if any. And yes, users may specialize iterator_category for a program-defined type. Go off, customize away π«Ά
The four flavors:
- The primary template is an empty struct. That's it. Empty. Nothing inside. A little void where a heart should be π
- This one's the specialization for pointers. If
Tis an object type, it provides a member typetypeequal toranges::random_access_iterator_tag. Otherwise? There is no member type. Tough luck π - Specialization for const-qualified types.
- Specialization for types that define a public and accessible member type
iterator_category. IfT::iterator_categoryis the same as or derived from one of the iterator category tags in namespacestd, it gets mapped to the corresponding tag in the namespaceranges, as described down below β¬οΈ. Otherwise, it provides a member typetypeequal toT::iterator_category.
And here's the mapping tea β (this is the "as described below" part, you're welcome):
- If
T::iterator_categoryis the same as or derives fromstd::random_access_iterator_tag, it provides a member typetypeequal toranges::random_access_iterator_tag. πββοΈπ¨ - Otherwise, if
T::iterator_categoryis the same as or derives fromstd::bidirectional_iterator_tag, it provides a member typetypeequal toranges::bidirectional_iterator_tag. βοΈ - Otherwise, if
T::iterator_categoryis the same as or derives fromstd::forward_iterator_tag, it provides a member typetypeequal toranges::forward_iterator_tag. β‘οΈ - Otherwise, if
T::iterator_categoryis the same as or derives fromstd::input_iterator_tag, it provides a member typetypeequal toranges::input_iterator_tag. π₯ - Otherwise, if
T::iterator_categoryis the same as or derives fromstd::output_iterator_tag, there is no member type. π€π«
π Helper alias template π
Also there's this little cutie, from the (ranges TS):
template< class T >
using iterator_category_t = typename ranges::iterator_category<T>::type;
πΈ Example πΈ
This section is incomplete. Reason: no example.
No example, bestie. None. Zero. It's giving "trust me bro" π The page literally says so, I'm not hiding anything from you.
π¦ See also π¦
input_iterator_tagoutput_iterator_tagforward_iterator_tagbidirectional_iterator_tagrandom_access_iterator_tagcontiguous_iterator_tag(C++20)
β¦all of those are empty class types used to indicate iterator categories (they're (class) types, ngl). π«
iterator_traitsβ the compatibility traits class that collects an iterator's associated types (the page also chucks an(alias template)label down here with it π).
π Category π
- Todo no example π
ok that's the whole page, you ate that π
β¨ β this was std::experi...or_category(3) from http://cppreference.com, dated 2024.06.10. mwah, go read some more manpages bestie πππ«Ά
π¦ 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