Files
cppdraft_translate/cppdraft/readable/traits.md
2025-10-25 03:02:53 +03:00

5.0 KiB
Raw Blame History

[readable.traits]

24 Iterators library [iterators]

24.3 Iterator requirements [iterator.requirements]

24.3.2 Associated types [iterator.assoc.types]

24.3.2.2 Indirectly readable traits [readable.traits]

1

#

To implement algorithms only in terms of indirectly readable types, it is often necessary to determine the value type that corresponds to a particular indirectly readable type.

Accordingly, it is required that if R is the name of a type that models the indirectly_readable concept ([iterator.concept.readable]), the typeiter_value_t be defined as the indirectly readable type's value type.

🔗

template struct cond-value-type { }; // exposition onlytemplaterequires is_object_vstruct cond-value-type {using value_type = remove_cv_t;};

templateconcept has-member-value-type = requires { typename T::value_type; }; // exposition onlytemplateconcept has-member-element-type = requires { typename T::element_type; }; // exposition onlytemplate struct indirectly_readable_traits { };

templatestruct indirectly_readable_traits<T*>: cond-value-type { };

templaterequires is_array_vstruct indirectly_readable_traits {using value_type = remove_cv_t<remove_extent_t>;};

templatestruct indirectly_readable_traits: indirectly_readable_traits { };

template<has-member-value-type T>struct indirectly_readable_traits: cond-value-type { };

template<has-member-element-type T>struct indirectly_readable_traits: cond-value-type { };

template<has-member-value-type T>requires has-member-element-typestruct indirectly_readable_traits { };

template<has-member-value-type T>requires has-member-element-type &&same_as<remove_cv_t, remove_cv_t>struct indirectly_readable_traits: cond-value-type { };

template using iter_value_t = see below;

2

#

Let RI be remove_cvref_t.

The type iter_value_t denotes

indirectly_readable_traits::value_type if iterator_traits names a specialization generated from the primary template, and

iterator_traits::value_type otherwise.

3

#

Class template indirectly_readable_traits may be specialized on program-defined types.

4

#

[Note 1:

Some legacy output iterators define a nested type named value_type that is an alias for void.

These types are not indirectly_readable and have no associated value types.

— end note]

5

#

[Note 2:

Smart pointers like shared_ptr are indirectly_readable and have an associated value type, but a smart pointer like shared_ptr is not indirectly_readable and has no associated value type.

— end note]