Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
repeat_type.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_MANIPULATION_REPEAT_TYPE_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_REPEAT_TYPE_HPP_
7
8// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9#include "arene/base/stdlib_choice/cstddef.hpp"
10
11namespace arene {
12namespace base {
13
14namespace repeat_type_detail {
15// forward declares
16template <std::size_t N, template <typename...> class T, typename Arg, typename... Args>
17struct repeat_type_impl;
18
19template <std::size_t N, template <typename...> class T, typename U, typename Arg, typename... Args>
20struct repeat_type_impl_ex;
21} // namespace repeat_type_detail
22
23/// @brief Repeat a template argument a specified number of times.
24/// @tparam N The number of times to repeat.
25/// @tparam T The templated type.
26/// @tparam Arg The repeated argument.
27template <std::size_t N, template <typename...> class T, typename Arg>
29 /// @brief The resulting type
30 using type = typename repeat_type_detail::repeat_type_impl<N - 1UL, T, Arg>::type;
31};
32
33/// @brief Repeat a template argument a specified number of times.
34/// @details The partial specialization that terminates repetition.
35/// @tparam T The templated type.
36/// @tparam Arg The repeated argument.
37template <template <typename...> class T, typename Arg>
38struct repeat_type<0UL, T, Arg> {
39 /// @brief The resulting type
40 using type = T<>;
41};
42
43/// @brief Repeat a template argument a specified number of times.
44/// @tparam N The number of times to repeat.
45/// @tparam T The templated type.
46/// @tparam Arg The repeated argument.
47template <std::size_t N, template <typename...> class T, typename Arg>
48using repeat_type_t = typename repeat_type<N, T, Arg>::type;
49
50/// @brief Repeat a template argument a specified number of times with an extra leading template argument.
51/// @tparam N The number of times to repeat.
52/// @tparam T The templated type.
53/// @tparam U The extra leading template argument.
54/// @tparam Arg The repeated argument.
55template <std::size_t N, template <typename...> class T, class U, typename Arg>
57 /// @brief The resulting type
58 using type = typename repeat_type_detail::repeat_type_impl_ex<N - 1UL, T, U, Arg>::type;
59};
60
61/// @brief Repeat a template argument a specified number of times with an extra leading template argument.
62/// @details The partial specialization that terminates repetition.
63/// @tparam T The templated type.
64/// @tparam U The extra leading template argument.
65/// @tparam Arg The repeated argument.
66template <template <typename...> class T, class U, typename Arg>
67struct repeat_type_ex<0UL, T, U, Arg> {
68 /// @brief The resulting type
69 using type = T<U>;
70};
71
72namespace repeat_type_detail {
73/// @brief A helper for repeating a template argument a specified number of times.
74/// @tparam N The number of times to repeat.
75/// @tparam T The templated type.
76/// @tparam Arg The repeated argument.
77/// @tparam Args The remaining template arguments.
78template <std::size_t N, template <typename...> class T, typename Arg, typename... Args>
79struct repeat_type_impl {
80 /// @brief The resulting type
81 using type = typename repeat_type_impl<N - 1UL, T, Arg, Arg, Args...>::type;
82};
83
84/// @brief A helper for repeating a template argument a specified number of
85/// times.
86/// @details The partial specialization that terminates repetition.
87/// @tparam T The templated type.
88/// @tparam Arg The repeated argument.
89/// @tparam Args The remaining template arguments.
90template <template <typename...> class T, typename Arg, typename... Args>
91struct repeat_type_impl<0UL, T, Arg, Args...> {
92 /// @brief The resulting type
93 using type = T<Arg, Args...>;
94};
95
96/// @brief A helper for repeating a template argument a specified number of
97/// times with an extra leading template argument.
98/// @tparam N The number of times to repeat.
99/// @tparam T The templated type.
100/// @tparam U The extra leading template argument.
101/// @tparam Arg The repeated argument.
102/// @tparam Args The remaining template arguments.
103template <std::size_t N, template <typename...> class T, typename U, typename Arg, typename... Args>
104struct repeat_type_impl_ex {
105 /// @brief The resulting type
106 using type = typename repeat_type_impl_ex<N - 1UL, T, U, Arg, Arg, Args...>::type;
107};
108
109/// @brief A helper for repeating a template argument a specified number of
110/// times with an extra leading template argument.
111/// @details The partial specialization that terminates repetition.
112/// @tparam T The templated type.
113/// @tparam U The extra leading template argument.
114/// @tparam Arg The repeated argument.
115/// @tparam Args The remaining template arguments.
116template <template <typename...> class T, class U, typename Arg, typename... Args>
117struct repeat_type_impl_ex<0UL, T, U, Arg, Args...> {
118 /// @brief The resulting type
119 using type = T<U, Arg, Args...>;
120};
121} // namespace repeat_type_detail
122
123} // namespace base
124} // namespace arene
125
126#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_REPEAT_TYPE_HPP_
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
Repeat a template argument a specified number of times with an extra leading template argument.
Definition repeat_type.hpp:56
Repeat a template argument a specified number of times.
Definition repeat_type.hpp:28