Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
at.hpp
Go to the documentation of this file.
1// Copyright 2024, Toyota Motor Corporation
2//
3// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
4
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_AT_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_AT_HPP_
7
8// IWYU pragma: private, include "arene/base/type_list.hpp"
9// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
10
11// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
12#include "arene/base/stdlib_choice/cstddef.hpp"
13#include "arene/base/stdlib_choice/integer_sequence.hpp"
14#include "arene/base/stdlib_choice/tuple_element.hpp"
15#include "arene/base/type_list/type_list.hpp"
16#include "arene/base/type_traits/type_identity.hpp"
17// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
18
19namespace arene {
20namespace base {
21
22namespace type_lists {
23
24/// @cond INTERNAL
25
26namespace at_detail {
27
28/// @brief Local alias for type_list.
29/// @tparam Tn The elements of the list
30template <class... Tn>
31using tl = arene::base::type_list<Tn...>;
32
33/// @brief An implementation class that derives from all the specified base classes.
34/// @tparam Bases The list of base classes to derive from; must not contain
35/// duplicates
36template <typename... Bases>
37class idx : public Bases... {};
38
39/// @brief A tag type specifying the index of an element and its type
40/// @tparam Index The index of this element in the type list
41/// @tparam T The type of this element
42template <std::size_t Index, typename T>
43class idx_el {};
44
45// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
46// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
47/// @brief Unimplemented function, the return type of which is the type of the
48/// specified element in a type list
49/// @tparam Index The index of the element to get the type of
50/// @tparam T The type of that element
51/// @return An instance of @c T
52template <std::size_t Index, typename T>
53inline auto get_element_type(idx_el<Index, T> const&) -> arene::base::type_identity<T>;
54// parasoft-end-suppress CERT_C-EXP37-a-3
55// parasoft-end-suppress AUTOSAR-M3_3_2-a
56
57// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
58// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
59/// @brief Unimplemented function, the return type of which is a class that derives
60/// from an instance of @c idx_el for each element in the
61/// type list.
62/// @tparam Indices The indices of the elements
63/// @tparam Types The types of the elements
64/// @return An instance of @c idx
65template <std::size_t... Indices, typename... Types>
66inline auto make_idx(std::index_sequence<Indices...>, tl<Types...>) -> idx<idx_el<Indices, Types>...> const&;
67// parasoft-end-suppress CERT_C-EXP37-a-3
68// parasoft-end-suppress AUTOSAR-M3_3_2-a
69
70/// @brief Get the n-th element from a type list
71///
72/// @tparam Index the index of the element to get
73/// @tparam TL the type list for which to get the element
74/// @pre @c TL is an instantiation of a type-list
75/// @pre <c>Index < TL::Size()</c>
76template <std::size_t Index, typename L0>
77class at_impl;
78
79/// @brief Get the n-th element from a type list.
80///
81/// @tparam Index the index of the element to get
82/// @tparam Types the elements in the type list
83template <std::size_t Index, template <typename...> class TypeList0, typename... Tn0>
84class at_impl<Index, TypeList0<Tn0...>> {
85 public:
86 static_assert(Index < sizeof...(Tn0), "Index must be less than the number of types in the list");
87 /// @brief The element type for Index
88 using type = typename decltype(::arene::base::type_lists::at_detail::get_element_type<Index>(
89 ::arene::base::type_lists::at_detail::make_idx(std::make_index_sequence<sizeof...(Tn0)>(), tl<Tn0...>{})
90 ))::type;
91};
92
93} // namespace at_detail
94
95/// @endcond
96
97/// @brief Get the n-th element from a type list
98///
99/// @tparam L0 An instantiation of a type-list that holds the types to index
100/// @tparam Index the index of the element to get
101/// @pre @c L0 is a type-list
102/// @pre <c>Index < size<L0></c>
103template <class L0, std::size_t Index>
104using at = arene::base::type_lists::at_detail::at_impl<Index, L0>;
105
106/// @brief Get the n-th element from a type list
107///
108/// @tparam L0 An instantiation of a type-list that holds the types to index
109/// @tparam Index the index of the element to get
110/// @pre @c L0 is a type-list
111/// @pre <c>Index < size<L0></c>
112template <class L0, std::size_t Index>
113using at_t = typename at<L0, Index>::type;
114
115} // namespace type_lists
116} // namespace base
117} // namespace arene
118
119// parasoft-begin-suppress AUTOSAR-A14_7_2-a-2 "False positive: 'type_list' is defined in type_list.hpp included above"
120/// @brief A meta function to retrieve the specified element from a type list.
121///
122/// The @c type member is an alias of the resultant type
123/// @tparam I The index of the element to retrieve
124/// @tparam Tn The elements of the type list
125template <std::size_t I, class... Tn>
126class std::tuple_element<I, arene::base::type_list<Tn...>>
127 : public arene::base::type_lists::at_detail::at_impl<I, arene::base::type_list<Tn...>> {};
128// parasoft-end-suppress AUTOSAR-A14_7_2-a-2
129
130#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_AT_HPP_
Definition apply_all.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10