Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
filter.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_FILTER_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_FILTER_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
#
include
"arene/base/type_list/flat_map.hpp"
12
#
include
"arene/base/type_list/type_list.hpp"
13
#
include
"arene/base/type_traits/conditional.hpp"
14
15
namespace
arene
{
16
namespace
base
{
17
18
namespace
type_lists
{
19
20
/// @cond INTERNAL
21
22
namespace
filter_detail {
23
24
/// @brief Local alias for type_list.
25
/// @tparam Tn The elements of the list
26
template
<
class
... Tn>
27
using
tl = arene::base::type_list<Tn...>;
28
29
/// @brief A class template meta-function that returns a type list that contains
30
/// only the elements in the type list for which Filter<>::value was true
31
///
32
/// @tparam TypeList The type list use to produce the result.
33
/// @tparam Filter The unary predicate to invoke.
34
/// @return TypeList<..>
35
template
<
template
<
class
...>
class
Filter>
36
struct
apply_filter {
37
/// @brief @p filter is a type list that is empty when the result of invoking
38
/// @p Filter<> with @p T is false and otherwise has a single element @p T
39
template
<
class
T>
40
using
filter = conditional_t<
41
Filter<T>::value,
42
// keep
43
tl<T>,
44
// discard
45
tl<>>;
46
};
47
48
}
// namespace filter_detail
49
50
/// @endcond
51
52
/// @brief Filter a type-list to remove elements that don't match the supplied
53
/// @c Filter.
54
///
55
/// @tparam L0 An instantiation of type-list that holds the types to filter.
56
/// @tparam Filter A constexpr bool meta-function that accepts a single type
57
/// parameter and provides a boolean that is @c true if the type should be
58
/// included in the list, @c false otherwise.
59
/// @return TypeList<T...>
60
template
<
class
L0
,
template
<
class
>
class
Filter
>
61
using
filter
=
arene
::
base
::
type_lists
::
62
flat_map
<
L0
,
arene
::
base
::
type_lists
::
filter_detail
::
apply_filter
<
Filter
>::
template
filter
>;
63
64
/// @brief Filter a type-list to remove elements that don't match the supplied
65
/// @c Filter.
66
///
67
/// @tparam L0 An instantiation of type-list that holds the types to filter.
68
/// @tparam Filter A constexpr bool meta-function that accepts a single type
69
/// parameter and provides a boolean that is @c true if the type should be
70
/// included in the list, @c false otherwise.
71
/// @return TypeList<T...>
72
template
<
class
L0
,
template
<
class
>
class
Filter
>
73
using
filter_t
=
typename
filter
<
L0
,
Filter
>::
type
;
74
75
}
// namespace type_lists
76
}
// namespace base
77
}
// namespace arene
78
79
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_FILTER_HPP_
arene::base::type_lists
Definition
apply_all.hpp:14
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
type_list
filter.hpp
Generated by
1.13.2