std::experi...::value_type(3)

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

πŸ’– std::experi...::value_type(3) πŸ’–

okay so this is straight from the C++ Standard Libary manual, and the main character is std::experimental::ranges::value_type ✨


🌸 NAME 🌸

std::experimental::ranges::value_type β€” std::experimental::ranges::value_type

yes bestie, that’s the same name twice; the manpage said it like that and I’m not gonna pretend otherwise πŸ’…


πŸ¦‹ Synopsis πŸ¦‹

Defined in header <experimental/ranges/iterator>
template< class I >                                          (1)
struct value_type {};
template< class T >                                          (2)
struct value_type<T*>;
template< class I >

    requires std::is_array<I>::value                         (3)

struct value_type<I> : value_type<std::decay_t<I>> {};
template< class T >                                          (4)
struct value_type<const T> : value_type<std::decay_t<T>> {};
template< class T >

    requires requires { typename T::value_type; }            (5)

struct value_type<T>;
template< class T >

    requires requires { typename T::element_type; }          (6)

struct value_type<T>;

So what’s the vibe? It computes the associated value type of the type I, if any. And yes, users may specialize value_type for a program-defined type 🫢

Here’s the numbered rundown, no cap:

  • (1) β€” the primary template is an empty struct. Literally struct value_type {}; and nothing else.
  • (2) β€” specialization for pointers. If T is an object type, it provides a member type type equal to std::remove_cv_t<T>. Otherwise, there is no member type.
  • (3) β€” specialization for array types. The code is struct value_type<I> : value_type<std::decay_t<I>> {}; under requires std::is_array<I>::value.
  • (4) β€” specialization for const-qualified types. The code is struct value_type<const T> : value_type<std::decay_t<T>> {};.
  • (5) β€” specialization for types that define a public and accessible member type value_type. If T::value_type is an object type, it provides a member type type equal to T::value_type. Otherwise, there is no member type.
  • (6) β€” specialization for types that define a public and accessible member type element_type (e.g., std::shared_ptr). If T::element_type is an object type, it provides a member type type equal to std::remove_cv_t<typename T::element_type>. Otherwise, there is no member type.

πŸ¦‹ Notes πŸ¦‹

⚠️ bestie, listen: if a type contains both a value_type member and a element_type member, then the specializations (5) and (6) are ambiguous. That’s the drama.

value_type is intended for use with Readable types such as iterators. It is not intended for use with ranges.


πŸ“ Example πŸ“

🚧 This section is incomplete Reason: no example

not me showing up with an empty example section πŸ’€ but that’s literally what the page says.


🌈 See also 🌈

  • Readable (concept) β€” specifies that a type is readable by applying operator *.
  • iterator_traits (alias template) β€” compatibility traits class that collects an iterator’s associated types.

πŸŽ€ Category: πŸŽ€

  • * Todo no example

okay that’s the whole page, bestie 🫢 source/version vibes from http://cppreference.com, dated 2024.06.10, and the footer signature is std::experi...::value_type(3). mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from