Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
drop.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_DROP_HPP_
5#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_DROP_HPP_
6
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"
13
14namespace arene {
15namespace base {
16namespace type_lists {
17
18namespace drop_detail {
19
20// parasoft-begin-suppress CERT_C-EXP37-a "False positive: The rule does not mention naming all parameters"
21// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: This should not have the static keyword applied"
22/// @brief helper removing the first @c Count types
23/// @tparam Count number of types to remove
24/// @tparam Is indices
25/// @tparam List type list type
26/// @tparam Ts types
27/// @return @c List after removing the first @c Count types from @c Ts...
28template <std::size_t Count, std::size_t... Is, template <class...> class List, class... Ts>
29auto drop_impl(std::index_sequence<Is...>, List<Ts...>) -> List<at_t<List<Ts...>, Count + Is>...>;
30// parasoft-end-suppress AUTOSAR-M3_3_2-a
31// parasoft-end-suppress CERT_C-EXP37-a
32
33/// @brief implementation helper for drop
34/// @tparam List type list
35/// @tparam Count number of types to drop
36///
37/// Undefined primary template.
38template <class List, std::size_t Count, class = constraints<>>
39class drop;
40
41/// @brief implementation helper for drop
42/// @tparam List type list type
43/// @tparam Ts types
44/// @tparam Count number of types to drop
45///
46/// Specialization for @c Count less than the size of @c List<Ts...>
47template <template <class...> class List, class... Ts, std::size_t Count>
48class drop<List<Ts...>, Count, constraints<std::enable_if_t<(Count < sizeof...(Ts))>>> {
49 public:
50 /// @brief resulting type list
51 using type =
52 decltype(drop_impl<Count>(std::make_index_sequence<sizeof...(Ts) - Count>{}, std::declval<List<Ts...>>()));
53};
54
55/// @brief implementation helper for drop
56/// @tparam List type list type
57/// @tparam Ts types
58/// @tparam Count number of types to drop
59///
60/// Specialization for @c Count greater than or equal to the size of @c List<Ts...>
61template <template <class...> class List, class... Ts, std::size_t Count>
62class drop<List<Ts...>, Count, constraints<std::enable_if_t<(Count >= sizeof...(Ts))>>> {
63 public:
64 /// @brief resulting type list
65 using type = List<>;
66};
67
68} // namespace drop_detail
69
70/// @brief drops types from the front of a type list
71/// @tparam List type-list-like
72/// @tparam Count number of types to drop
73///
74/// For any type-list-like @c List, provides the member typedef @c type which is
75/// the same as @c List but with the first @c Count types omitted. If @c Count
76/// exceeds the number of types in @c List, @c type specifies an "empty"
77/// type-list.
78///
79/// Usage:
80/// @snippet docs/examples/type_list_examples.cpp drop_example
81///
82///
83template <class List, std::size_t Count>
84using drop = drop_detail::drop<List, Count>;
85
86/// @brief drops types from the front of a type list
87/// @tparam List type-list-like
88/// @tparam Count number of types to drop
89/// @copydoc drop
90template <class List, std::size_t Count>
92
93} // namespace type_lists
94} // namespace base
95} // namespace arene
96
97#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_DROP_HPP_
Definition apply_all.hpp:14
drop_detail::drop< List, Count > drop
drops types from the front of a type list
Definition drop.hpp:84
typename at< L0, Index >::type at_t
Get the n-th element from a type list.
Definition at.hpp:113
typename drop< List, Count >::type drop_t
drops types from the front of a type list
Definition drop.hpp:91
Definition accumulate.hpp:37
typename constraints_impl::constraints< EnableIfs... >::type constraints
Helper used to express template constraints in a consistent way using std::enable_if_t.
Definition constraints.hpp:51
Definition accumulate.hpp:36
make_integer_sequence< size_t, Size > make_index_sequence
A helper alias template for make_integer_sequence<size_t, Size>
Definition integer_sequence.hpp:224
integer_sequence< size_t, Ints... > index_sequence
A helper alias template for integer_sequence<size_t, Ints>
Definition integer_sequence.hpp:218
::size_t size_t
A type suitable for holding the size of an object.
Definition cstddef.hpp:29
typename enable_if< Condition, Type >::type enable_if_t
Type alias to support constraining templates. Is an alias for the specified type if the Condition is ...
Definition enable_if.hpp:41
auto declval() noexcept -> T &&
A dummy function that is declared but not defined, with a user-specified return type,...