Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
remove_nth.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::remove_nth"
2// Copyright 2026, Toyota Motor Corporation
3//
4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
5#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_REMOVE_NTH_HPP_
6#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_REMOVE_NTH_HPP_
7
8#include "arene/base/stdlib_choice/cstddef.hpp"
9#include "arene/base/stdlib_choice/integer_sequence.hpp"
10#include "arene/base/type_list/at.hpp"
11#include "arene/base/type_traits/type_identity.hpp"
12
13namespace arene {
14namespace base {
15namespace type_lists {
16
17/// @cond INTERNAL
18
19namespace remove_nth_detail {
20
21// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
22// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
23/// @brief implementation function for selecting the specified elements from a type list
24/// @tparam List Type list template
25/// @tparam Ts The types in the list
26/// @tparam Js The indices of the elements to return
27/// @return type list with the selected elements
28template <template <class...> class List, class... Ts, std::size_t... Js>
29auto select_elements_from_impl(type_identity<List<Ts...>>, std::index_sequence<Js...>)
30 -> List<type_lists::at_t<List<Ts...>, Js>...>;
31// parasoft-end-suppress CERT_C-EXP37-a-3
32// parasoft-end-suppress AUTOSAR-M3_3_2-a
33
34/// @brief A type alias for a type list with the selected elements from the source list
35/// @tparam List The source type list
36/// @tparam Indices An instance of @c std:index_sequence with the indices of the selected elements
37template <typename List, typename Indices>
38using select_elements_from_t = decltype(select_elements_from_impl(type_identity<List>{}, Indices{}));
39
40// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
41/// @brief implementation function for getting an index sequence with the nth element removed
42/// @tparam IndexToRemove The index to remove
43/// @tparam Js The indices of the elements
44/// @return index sequence with the specified index removed
45template <std::size_t IndexToRemove, std::size_t... Js>
46auto remove_nth_helper(std::index_sequence<Js...>) -> std::index_sequence<((Js < IndexToRemove) ? Js : (Js + 1))...>;
47// parasoft-end-suppress CERT_C-EXP37-a-3
48
49/// @brief implementation type for @c remove_nth
50/// @tparam List type list
51/// @tparam Index the index of the entry to remove
52template <typename List, std::size_t Index>
53class remove_nth_impl;
54
55/// @brief implementation type for @c remove_nth
56/// @tparam List type list
57/// @tparam Ts types
58/// @tparam Index the index of the entry to remove
59template <template <class...> class List, class... Ts, std::size_t Index>
60class remove_nth_impl<List<Ts...>, Index> {
61 public:
62 static_assert(Index < sizeof...(Ts), "The index must be less than the size of the list");
63
64 /// @brief type list with nth removed
65 using type = select_elements_from_t<
66 List<Ts...>,
67 decltype(remove_nth_helper<Index>(std::make_index_sequence<sizeof...(Ts) - 1>{}))>;
68};
69
70} // namespace remove_nth_detail
71
72/// @endcond
73
74/// @brief Filter a type-list to remove the element at the specified index
75///
76/// @tparam List An instantiation of a type-list that holds the types to filter
77/// @tparam Index the index of the element to remove
78/// @pre @c List is a type-list
79template <class List, std::size_t Index>
80using remove_nth = arene::base::type_lists::remove_nth_detail::remove_nth_impl<List, Index>;
81
82/// @brief Filter a type-list to remove the element at the specified index
83///
84/// @tparam List An instantiation of a type-list that holds the types to filter
85/// @tparam Index the index of the element to remove
86/// @pre @c List is a type-list
87/// @pre <c>Index < size<List></c>
88template <class List, std::size_t Index>
90
91} // namespace type_lists
92} // namespace base
93} // namespace arene
94
95#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_REMOVE_NTH_HPP_
Definition apply_all.hpp:14
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10