Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
indirectly_readable_traits.hpp
Go to the documentation of this file.
1// Copyright 2026, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_INDIRECTLY_READABLE_TRAITS_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_INDIRECTLY_READABLE_TRAITS_HPP_
7
9#include "arene/base/iterator/detail/cond_value_type.hpp"
10#include "arene/base/iterator/detail/has_member_element_type.hpp"
11#include "arene/base/iterator/detail/has_member_value_type.hpp"
12#include "arene/base/stdlib_choice/enable_if.hpp"
13#include "arene/base/stdlib_choice/is_array.hpp"
14#include "arene/base/stdlib_choice/is_same.hpp"
15#include "arene/base/stdlib_choice/remove_cv.hpp"
16#include "arene/base/stdlib_choice/remove_extent.hpp"
17
18// IWYU pragma: private, include "arene/base/iterator.hpp"
19// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
20
21namespace arene {
22namespace base {
23
24namespace indirectly_readable_traits_detail {
25
26/// @brief Helper trait for implementing @c indirectly_readable_traits .
27/// @tparam Itr The input type for which to determine the @c value_type of.
28/// @see arene::base::indirectly_readable_traits<Itr>
29template <typename Itr, typename = constraints<>>
30class indirectly_readable_traits {};
31
32/// @brief Specialization of @c indirectly_readable_traits for array types.
33/// @tparam Itr The array type for which to determine the @c value_type of.
34/// @see arene::base::indirectly_readable_traits<Itr>
35template <typename Itr>
36class indirectly_readable_traits<Itr, constraints<std::enable_if_t<std::is_array<Itr>::value>>> {
37 public:
38 // parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: identifier 'value_type' does not hide anything"
39 /// @brief The value type corresponding to the array element type.
41 // parasoft-end-suppress AUTOSAR-A2_10_1-d
42};
43
44/// @brief Specialization of @c indirectly_readable_traits for types with a @c value_type but no @c element_type.
45/// @tparam Itr The input type for which to determine the @c value_type of.
46/// @see arene::base::indirectly_readable_traits<Itr>
47template <typename Itr>
48class indirectly_readable_traits<
49 Itr,
51 std::enable_if_t<iterator_detail::has_member_value_type_v<Itr>>,
52 std::enable_if_t<!iterator_detail::has_member_element_type_v<Itr>>>>
53 : public iterator_detail::cond_value_type<typename Itr::value_type> {};
54
55/// @brief Specialization of @c indirectly_readable_traits for types with an @c element_type but no @c value_type.
56/// @tparam Itr The input type for which to determine the @c value_type of.
57/// @see arene::base::indirectly_readable_traits<Itr>
58template <typename Itr>
59class indirectly_readable_traits<
60 Itr,
62 std::enable_if_t<!iterator_detail::has_member_value_type_v<Itr>>,
63 std::enable_if_t<iterator_detail::has_member_element_type_v<Itr>>>>
64 : public iterator_detail::cond_value_type<typename Itr::element_type> {};
65
66/// @brief Specialization of @c indirectly_readable_traits for types with both a @c value_type and an @c element_type
67/// where the two types are the same (ignoring cv-qualifiers).
68/// @tparam Itr The input type for which to determine the @c value_type of.
69/// @see arene::base::indirectly_readable_traits<Itr>
70template <typename Itr>
71class indirectly_readable_traits<
72 Itr,
74 std::enable_if_t<iterator_detail::has_member_value_type_v<Itr>>,
75 std::enable_if_t<iterator_detail::has_member_element_type_v<Itr>>,
77 std::is_same<std::remove_cv_t<typename Itr::value_type>, std::remove_cv_t<typename Itr::element_type>>::
78 value>>> : public iterator_detail::cond_value_type<typename Itr::value_type> {};
79
80/// @brief Specialization of @c indirectly_readable_traits for types with both a @c value_type and an @c element_type
81/// where the two types are different (ignoring cv-qualifiers).
82/// @tparam Itr The input type for which to determine the @c value_type of.
83/// @see arene::base::indirectly_readable_traits<Itr>
84template <typename Itr>
85class indirectly_readable_traits<
86 Itr,
88 std::enable_if_t<iterator_detail::has_member_value_type_v<Itr>>,
89 std::enable_if_t<iterator_detail::has_member_element_type_v<Itr>>,
90 std::enable_if_t<!std::is_same<
91 std::remove_cv_t<typename Itr::value_type>,
92 std::remove_cv_t<typename Itr::element_type>>::value>>> {};
93
94} // namespace indirectly_readable_traits_detail
95
96/// @brief Determines the @c value_type of an input indirectly readable type, which is a type whose value is "readable"
97/// via the dereference operator such as iterators, pointers, etc.
98/// @tparam Itr The input type for which to determine the @c value_type of.
99///
100/// Let @c cond_value_type<T> be an exposition only trait which will have a member typedef @c value_type defined as
101/// @c std::remove_cv_t<T> if @c std::is_object<T> is satisfied, otherwise @c value_type will not be defined .
102///
103/// The presence/type of the member typedef @c value_type is determined based on the following selecting rules:
104/// 1. If the input type is an array, @c std::remove_cv_t<std::remove_extent_t<T>> where @c T is the pointed-to type .
105/// 2. If the input type has a member typedef @c value_type but not @c element_type ,
106/// <c>cond_value_type<typename Itr::value_type></c>
107/// 3. If the input type has a member typedef @c element_type but not @c value_type ,
108/// <c>cond_value_type<typename Itr::element_type></c>
109/// 4. If the input type has both member typedefs @c value_type and @c element_type and they are the same (ignoring
110/// cv-qualifiers), <c>cond_value_type<typename Itr::value_type></c>
111/// 5. If the input type has both member typedefs @c value_type and @c element_type and they are different (ignoring
112/// cv-qualifiers), then @c value_type will not be defined.
113/// Otherwise, @c value_type will not be defined.
114///
115/// Users are free to specialize @c indirectly_readable_traits for their own types.
116template <typename Itr>
117class indirectly_readable_traits : public indirectly_readable_traits_detail::indirectly_readable_traits<Itr> {};
118
119/// @brief Specialization of @c indirectly_readable_traits for const types.
120/// @tparam Itr The input type for which to determine the @c value_type of.
121/// @see arene::base::indirectly_readable_traits<Itr>
122template <typename Itr>
124
125/// @brief Specialization of @c indirectly_readable_traits for pointer types.
126/// @tparam T the pointed-to object type
127///
128/// Let @c cond_value_type<T> be an exposition only trait which will have a member typedef @c value_type defined as
129/// @c std::remove_cv_t<T> if @c std::is_object<T> is satisfied, otherwise @c value_type will not be defined .
130///
131/// Then @c indirectly_readable_traits<T*> is equivalent to @c cond_value_type<T> .
132template <typename T>
133class indirectly_readable_traits<T*> : public iterator_detail::cond_value_type<T> {};
134
135} // namespace base
136} // namespace arene
137
138#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_ITERATOR_INDIRECTLY_READABLE_TRAITS_HPP_
Determines the value_type of an input indirectly readable type, which is a type whose value is "reada...
Definition indirectly_readable_traits.hpp:117
Definition accumulate.hpp:37
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
typename remove_cv< T >::type remove_cv_t
An alias for T, but with top-level const and/or volatile qualifiers removed.
Definition remove_cv.hpp:64
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41