std::indire...dable_traits(3)

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

πŸ’– NAME πŸ’–

std::indirectly_readable_traits β€” std::indirectly_readable_traits. That’s the name section, bestie, and yes, it’s giving β€œiconic but slightly mysterious.” The page header is std::indire...dable_traits(3), from the C++ Standard Libary (yes, that spelling is on the page β€” we’re not fixing it πŸ’…).

This one computes the associated value type of the template argument. If that associated value type exists, it’s represented by the nested type value_type; otherwise, value_type is not defined. A program may specialize indirectly_readable_traits for a program-defined type. Periodt.


✨ Synopsis ✨

Defined in header <iterator>.

The declarations are all here, bestie β€” no cap, not one skipped:

template< class I >                                           (1)
(since C++20)
struct indirectly_readable_traits {};
template< class T >

struct indirectly_readable_traits<T*> :                       (2)
(since C++20)

    /* cond-value-type */<T> {};
template< class I >

    requires std::is_array_v<I>
struct indirectly_readable_traits<I>;                         (3)
(since C++20)

{ using value_type =
std::remove_cv_t<std::remove_extent_t<I>>; }
template< class T >

struct indirectly_readable_traits<const T> :                  (4)
(since C++20)

    indirectly_readable_traits<T> {};
template< /* has-member-value-type */ T >

struct indirectly_readable_traits<T> :                        (5)
(since C++20)

    /* cond-value-type */<typename T::value_type> {};
template< /* has-member-element-type */ T >

struct indirectly_readable_traits<T> :                        (6)
(since C++20)

    /* cond-value-type */<typename T::element_type> {};
template< /* has-member-value-type */ T >

    requires /* has-member-element-type */<T>                 (7)
(since C++20)

struct indirectly_readable_traits<T> {};
template< /* has-member-value-type */ T >

    requires /* has-member-element-type */<T> &&
             std::same_as<std::remove_cv_t<typename
T::element_type>,                                             (8)
(since C++20)
                          std::remove_cv_t<typename
T::value_type>>
struct indirectly_readable_traits<T> :

    /* cond-value-type */<typename T::value_type> {};

✨ Helper classes and concepts ✨

These are the exposition-only besties, iykyk:

template< class >                                             (1)
(exposition only*)
struct /* cond-value-type */ {};
template< class T >

    requires std::is_object_v<T>                              (2)
(exposition only*)
struct /* cond-value-type */ <T>

{ using value_type = std::remove_cv_t<T>; };
template< class T >

concept /* has-member-value-type */ =                         (3)
(exposition only*)

    requires { typename T::value_type; };
template< class T >

concept /* has-member-element-type */ =                       (4)
(exposition only*)

    requires { typename T::element_type; };

Computes the associated value type of the template argument. If the associated value type exists, it is represented by the nested type value_type, otherwise value_type is not defined. A program may specialize indirectly_readable_traits for a program-defined type.


🧠 Explanation 🧠

The specializations above can be informally described as below.

Given a type T, its associated value type V is determined as follows:

  • If T is const-qualified, V is the associated value type of const-unqualified T.
  • Otherwise, if T is an array type, V is the cv-unqualified array element type.
  • Otherwise, a conditional value type C is determined first:
    • If T is a pointer type, C is the pointed-to type.
    • Otherwise, if T has nested types value_type and element_type:
      • If these types are the same (not considering cv-qualification), C is typename T::value_type.
      • Otherwise, C is undefined.
    • Otherwise, if T has the nested type value_type but not element_type, C is typename T::value_type.
    • Otherwise, if T has the nested type element_type but not value_type, C is typename T::element_type.
    • Otherwise, C is undefined.
  • Then V is determined from C as follows:
    • If C is undefined, or C is not an object type, V is undefined.
    • Otherwise, V is cv-unqualified C.

πŸ“ Notes πŸ“

value_type is intended for use with indirectly_readable types such as iterators. It is not intended for use with ranges. That’s the whole note, bestie β€” important little vibe check 🫢.


πŸ§ͺ Example πŸ§ͺ

This section is incomplete Reason: no example

No example yet, so we’re not gonna invent one. We don’t do fanfic in the manual page πŸ’€.


🩹 Defect reports 🩹

The following behavior-changing defect reports were applied retroactively to previously published C++ standards.

  • DR 3446, applied to C++20. Behavior as published: specializations (5,6) were ambiguous for types having both value_type and element_type nested types. Correct behavior: added specialization (8).
  • DR 3541, applied to C++20. Behavior as published: LWG 3446 introduced hard error for ambiguous cases that value_type and element_type are different. Correct behavior: added specialization (7).

πŸ‘€ See also πŸ‘€

  • indirectly_readable (C++20) β€” specifies that a type is indirectly readable by applying operator * (concept).
  • iter_value_t (C++20) β€” computes the associated types of an iterator (alias template).
  • iter_reference_t (C++20) β€” computes the associated types of an iterator (alias template).
  • iter_const_reference_t (C++23) β€” computes the associated types of an iterator (alias template).
  • iter_difference_t (C++20) β€” computes the associated types of an iterator (alias template).
  • iter_rvalue_reference_t (C++20) β€” computes the associated types of an iterator (alias template).
  • iter_common_reference_t (C++20) β€” computes the associated types of an iterator (alias template).
  • iterator_traits β€” provides uniform interface to the properties of an iterator (class template).

🏷️ Category 🏷️

  • Todo no example

Okay bestie, that’s the whole page πŸ’– From the footer: source http://cppreference.com, version/date 2024.06.10, and the manual name std::indire...dable_traits(3) β€” mwah πŸ’‹βœ¨

πŸ“¦ where this page comes from