Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
flat_map.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_FLAT_MAP_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_FLAT_MAP_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/type_list/apply_all.hpp"
13#include "arene/base/type_list/concat.hpp"
14#include "arene/base/type_list/type_list.hpp"
15#include "arene/base/type_traits/type_identity.hpp"
16// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
17
18namespace arene {
19namespace base {
20
21namespace type_lists {
22
23/// @cond INTERNAL
24
25namespace flat_map_detail {
26
27/// @brief Local alias for type_list.
28/// @tparam Tn The elements of the list
29template <class... Tn>
30using tl = arene::base::type_list<Tn...>;
31
32/// @brief applies Apply<T> to each T in L0 (aka TypeList0<T...>) to produce
33/// TypeList<U...> by concatenating all the Apply<T> results
34template <class L0, template <class> class Apply>
35struct flat_map_impl;
36
37/// @brief The mapping of an empty list is an empty list
38/// @tparam TypeList0 The type list template
39/// @tparam Apply The metafunction to apply
40template <template <class...> class TypeList0, template <class> class Apply>
41struct flat_map_impl<TypeList0<>, Apply> {
42 /// @brief @p type is an empty list when the type list has no elements
43 using type = TypeList0<>;
44};
45
46/// @brief applies @c Apply<T> to each @c T in @c L0 (aka @c TypeList0<T...>) to produce
47/// @c TypeList<U...> by concatenating all the @c Apply<T> results
48/// @tparam TypeList0 The type list template
49/// @tparam T00 The first type in the type list
50/// @tparam T0n The other types in the type list.
51/// @tparam Apply The metafunction to apply
52template <template <class...> class TypeList0, class T00, class... T0n, template <class> class Apply>
53struct flat_map_impl<TypeList0<T00, T0n...>, Apply> {
54 private:
55 /// @brief invokes @c Apply with each element (start with tl<> so that the applied type-list is tl<..>)
56 using applied = arene::base::type_lists::concat_t<tl<>, Apply<T00>, Apply<T0n>...>;
57 /// @brief the result must use the @c TypeList0 template
58 using final = arene::base::type_lists::apply_all_t<applied, TypeList0>;
59
60 public:
61 /// @brief @p type is a type list that contains the result of invoking
62 /// @p Apply<> with each of the elements of the type list
63 using type = final;
64};
65
66} // namespace flat_map_detail
67
68/// @endcond
69
70/// @brief Produce TypeList<T...> by concatenating the type-list provided by
71/// the supplied class template meta-function @c Apply when it is invoked
72/// for each element in L0.
73///
74/// @tparam L0 An instantiation of a type-list that holds the types
75/// @tparam Apply A class template meta-function that accepts a single type
76/// parameter and produces a new type-list
77/// @return TypeList<T...>
78template <class L0, template <class> class Apply>
80
81/// @brief Produce TypeList<T...> by concatenating the type-list provided by
82/// the supplied class template meta-function @c Apply when it is invoked
83/// for each element in L0.
84///
85/// @tparam L0 An instantiation of a type-list that holds the types
86/// @tparam Apply A class template meta-function that accepts a single type
87/// parameter and produces a new type-list
88/// @return TypeList<T...>
89template <class L0, template <class> class Apply>
90using flat_map_t = typename flat_map<L0, Apply>::type;
91
92/// @brief collapse L0 aka TypeList0<TypeList1<T...>, .., TypeListN<U...>>
93/// into TypeList<T..., .., U...>
94///
95/// @tparam L0 A type-list that holds the type-lists to flatten.
96/// @return TypeList<T...>
97template <class L0>
99
100/// @brief collapse L0 aka TypeList0<TypeList1<T...>, .., TypeListN<U...>>
101/// into TypeList<T..., .., U...>
102///
103/// @tparam L0 A type-list that holds the type-lists to flatten.
104/// @return TypeList<T...>
105template <class L0>
106using flatten_t = typename flatten<L0>::type;
107
108} // namespace type_lists
109} // namespace base
110} // namespace arene
111
112#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_FLAT_MAP_HPP_
Definition apply_all.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10