Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
contains.hpp
Go to the documentation of this file.
1// parasoft-begin-suppress AUTOSAR-A2_8_1-a-2 "False positive: also defines arene::base::contains"
2
3// Copyright 2024, Toyota Motor Corporation
4//
5// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6#ifndef INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_CONTAINS_HPP_
7#define INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_CONTAINS_HPP_
8
9// IWYU pragma: private, include "arene/base/type_list.hpp"
10// IWYU pragma: friend "(arene/base(?!/tests)|stdlib/include/stdlib_detail)/.*"
11
12// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
13#include "arene/base/compiler_support/attributes.hpp"
14#include "arene/base/stdlib_choice/integral_constant.hpp"
15#include "arene/base/type_traits/is_one_of.hpp"
16// parasoft-end-suppress AUTOSAR-A16_2_2-a-2
17
18namespace arene {
19namespace base {
20
21namespace type_lists {
22
23/// @cond INTERNAL
24
25namespace contains_detail {
26
27/// @brief true if T is same as one of U... in L0 (aka TypeList0<U...>)
28template <class L0, class T>
29class contains_impl;
30
31/// @brief Implementation class for @c contains
32/// @tparam TypeList0 The type list template
33/// @tparam T0n The elements of the type list
34/// @tparam T The element to search for
35template <template <class...> class TypeList0, class... T0n, class T>
36class contains_impl<TypeList0<T0n...>, T> : public std::integral_constant<bool, is_one_of<T, T0n...>::value> {};
37
38} // namespace contains_detail
39
40/// @endcond
41
42/// @brief Query if a type-list contains a given type.
43///
44/// Evaluates to 'true' if T is an element of the type-list, L0,
45/// otherwise evaluates to 'false'.
46///
47/// @tparam L0 The type-list to search in.
48/// @tparam T The type to search for.
49/// @pre @c L0 is a type-list
50/// @return bool
51template <class L0, class T>
52// parasoft-begin-suppress AUTOSAR-M3_3_2-a "False positive: inline function used in multiple translation units"
53constexpr auto contains() -> bool {
54 return arene::base::type_lists::contains_detail::contains_impl<L0, T>::value;
55}
56// parasoft-end-suppress AUTOSAR-M3_3_2-a
57
58/// @brief Query if a type-list contains a given type.
59///
60/// Evaluates to 'true' if T is an element of the type-list, L0,
61/// otherwise evaluates to 'false'.
62///
63/// @tparam L0 The type-list to search in.
64/// @tparam T The type to search for.
65/// @pre @c L0 is a type-list
66/// @return bool
67template <class L0, class T>
68ARENE_MAYBE_UNUSED static constexpr bool contains_v{contains<L0, T>()};
69
70/// @brief Query if a type-list contains a given type.
71///
72/// Evaluates to 'true' if T is an element of the type-list, L0,
73/// otherwise evaluates to 'false'.
74///
75/// @tparam L0 The type-list to search in.
76/// @tparam T The type to search for.
77/// @pre @c L0 is a type-list
78template <class L0, class T>
79struct contains_t {
80 // parasoft-begin-suppress CERT_CPP-DCL56-a-3 "False positive: variable is initialized"
81 // parasoft-begin-suppress AUTOSAR-A3_3_2-a-2 "False positive: initializer is constant"
82 /// @brief The result of the query
83 static constexpr bool value{contains_v<L0, T>};
84 // parasoft-end-suppress AUTOSAR-A3_3_2-a-2
85 // parasoft-end-suppress CERT_CPP-DCL56-a-3
86};
87
88} // namespace type_lists
89} // namespace base
90} // namespace arene
91
92#endif // INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_LIST_CONTAINS_HPP_
Definition apply_all.hpp:14
static ARENE_MAYBE_UNUSED constexpr bool contains_v
Query if a type-list contains a given type.
Definition contains.hpp:68
constexpr auto contains() -> bool
Query if a type-list contains a given type.
Definition contains.hpp:53
Definition array_exceptions_disabled.cpp:11
Copyright 2026, Toyota Motor Corporation.
Definition array_exceptions_disabled.cpp:10
Query if a type-list contains a given type.
Definition contains.hpp:79
static constexpr bool value
The result of the query.
Definition contains.hpp:83