std::experi...or_category(3)

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

πŸ’– 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:

  1. The primary template is an empty struct. That's it. Empty. Nothing inside. A little void where a heart should be πŸ’€
  2. This one's the specialization for pointers. If T is an object type, it provides a member type type equal to ranges::random_access_iterator_tag. Otherwise? There is no member type. Tough luck πŸ™ˆ
  3. Specialization for const-qualified types.
  4. Specialization for types that define a public and accessible member type iterator_category. If T::iterator_category is the same as or derived from one of the iterator category tags in namespace std, it gets mapped to the corresponding tag in the namespace ranges, as described down below ⬇️. Otherwise, it provides a member type type equal to T::iterator_category.

And here's the mapping tea β˜• (this is the "as described below" part, you're welcome):

  • If T::iterator_category is the same as or derives from std::random_access_iterator_tag, it provides a member type type equal to ranges::random_access_iterator_tag. πŸƒβ€β™€οΈπŸ’¨
  • Otherwise, if T::iterator_category is the same as or derives from std::bidirectional_iterator_tag, it provides a member type type equal to ranges::bidirectional_iterator_tag. ↔️
  • Otherwise, if T::iterator_category is the same as or derives from std::forward_iterator_tag, it provides a member type type equal to ranges::forward_iterator_tag. ➑️
  • Otherwise, if T::iterator_category is the same as or derives from std::input_iterator_tag, it provides a member type type equal to ranges::input_iterator_tag. πŸ“₯
  • Otherwise, if T::iterator_category is the same as or derives from std::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_tag
  • output_iterator_tag
  • forward_iterator_tag
  • bidirectional_iterator_tag
  • random_access_iterator_tag
  • contiguous_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