Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
take.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#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_TAKE_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_TAKE_HPP_
6
7#include "arene/base/constraints/constraints.hpp"
8#include "arene/base/stdlib_choice/cstddef.hpp"
9#include "arene/base/stdlib_choice/declval.hpp"
10#include "arene/base/stdlib_choice/enable_if.hpp"
11#include "arene/base/stdlib_choice/integer_sequence.hpp"
12#include "arene/base/type_list/at.hpp"
13
14namespace arene {
15namespace base {
16namespace type_lists {
17
18namespace take_detail {
19
20// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
21/// @brief helper keeping the first @c Count types
22/// @tparam Count number of types to remove
23/// @tparam Is indices
24/// @tparam List type list type
25/// @tparam Ts types
26/// @return @c List after keeping the first @c Count types from @c Ts...
27template <std::size_t... Is, template <class...> class List, class... Ts>
28auto take_impl(std::index_sequence<Is...>, List<Ts...>) -> List<at_t<List<Ts...>, Is>...>;
29// parasoft-end-suppress CERT_C-EXP37-a
30
31/// @brief implementation helper for take
32/// @tparam List type list
33/// @tparam Count number of types to take
34///
35/// Undefined primary template.
36template <class List, std::size_t Count, class = constraints<>>
37class take;
38
39/// @brief implementation helper for take
40/// @tparam List type list type
41/// @tparam Ts types
42/// @tparam Count number of types to take
43///
44/// Specialization for @c Count less than the size of @c List<Ts...>
45template <template <class...> class List, class... Ts, std::size_t Count>
46class take<List<Ts...>, Count, constraints<std::enable_if_t<(Count < sizeof...(Ts))>>> {
47 public:
48 /// @brief resulting type list
49 using type = decltype(take_impl(std::make_index_sequence<Count>{}, std::declval<List<Ts...>>()));
50};
51
52/// @brief implementation helper for take
53/// @tparam List type list type
54/// @tparam Ts types
55/// @tparam Count number of types to take
56///
57/// Specialization for @c Count greater than or equal to the size of @c List<Ts...>
58template <template <class...> class List, class... Ts, std::size_t Count>
59class take<List<Ts...>, Count, constraints<std::enable_if_t<(Count >= sizeof...(Ts))>>> {
60 public:
61 /// @brief resulting type list
62 using type = List<Ts...>;
63};
64
65} // namespace take_detail
66
67/// @brief takes types from the front of a type list
68/// @tparam List type-list-like
69/// @tparam Count number of types to take
70///
71/// For any type-list-like @c List, provides the member typedef @c type which is
72/// the same as @c List but with the first @c Count types omitted. If @c Count
73/// exceeds the number of types in @c List, @c type specifies @c List.
74///
75/// Usage:
76/// @snippet docs/examples/type_list_examples.cpp take_example
77///
78///
79template <class List, std::size_t Count>
81
82/// @brief takes types from the front of a type list
83/// @tparam List type-list-like
84/// @tparam Count number of types to take
85/// @copydoc take
86template <class List, std::size_t Count>
87using take_t = typename take<List, Count>::type;
88
89} // namespace type_lists
90} // namespace base
91} // namespace arene
92
93#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_TAKE_HPP_
Definition apply_all.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10