Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
ebo_holder.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_MANIPULATION_EBO_HOLDER_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_EBO_HOLDER_HPP_
7
8
// parasoft-begin-suppress AUTOSAR-A16_2_2-a-2 "Arene Base aggregate headers permitted by A16-2-2 Permit #1"
9
#
include
"arene/base/compiler_support/diagnostics.hpp"
10
#
include
"arene/base/constraints/constraints.hpp"
11
#
include
"arene/base/stdlib_choice/enable_if.hpp"
12
#
include
"arene/base/stdlib_choice/forward.hpp"
13
#
include
"arene/base/stdlib_choice/is_class.hpp"
14
#
include
"arene/base/stdlib_choice/is_constructible.hpp"
15
#
include
"arene/base/stdlib_choice/is_default_constructible.hpp"
16
#
include
"arene/base/stdlib_choice/is_final.hpp"
17
#
include
"arene/base/stdlib_choice/is_same.hpp"
18
#
include
"arene/base/stdlib_choice/move.hpp"
19
// IWYU pragma: no_include "arene/base/stdlib_choice/remove_cv.hpp"
20
// IWYU pragma: no_include "arene/base/stdlib_choice/remove_reference.hpp"
21
#
include
"arene/base/type_list/type_list.hpp"
22
#
include
"arene/base/type_traits/remove_cvref.hpp"
23
24
// parasoft-begin-suppress CERT_C-EXP37-a-3 "False positive: The rule does not mention naming all parameters"
25
// parasoft-begin-suppress AUTOSAR-M2_10_1-a-2 "Similar names permitted by M2-10-1 Permit #1"
26
27
namespace
arene
{
28
namespace
base
{
29
30
// parasoft-begin-suppress AUTOSAR-A14_5_1-a "False positive: The single
31
// argument template constructor of 'ebo_holder' does not hide copy/move
32
// constructors via use of SFINAE."
33
// parasoft-begin-suppress AUTOSAR-A10_2_1 "False positive: There is no inheritance, and therefore functions cannot be
34
// hidden this way."
35
36
/// @brief A class to hold an instance of a type that is likely to be empty, such as a comparator or allocator, making
37
/// use of the empty base class optimization if possible
38
/// @tparam Tag A tag type to indicate this instance, for classes that have multiple values to hold
39
/// @tparam Value The type of the value to hold
40
// parasoft-begin-suppress AUTOSAR-A12_1_5-a "False positive: nowhere to use a delegating constructor here"
41
template
<
typename
Tag
,
typename
Value
,
bool
=
std
::
is_class
<
Value
>::
value
&& !
std
::
is_final
<
Value
>::
value
>
42
class
ebo_holder
{
43
/// @brief The instance of the value
44
Value
value_
;
45
46
public
:
47
// parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
48
/// @brief The type held by the EBO holder.
49
using
value_type
=
Value
;
50
// parasoft-end-suppress AUTOSAR-A2_10_1-d
51
52
/// @brief default constructor
53
/// @tparam T template parameter used to check constraints
54
///
55
/// Value initializes the contained value.
56
template
<
class
T
=
Value
,
constraints
<
std
::
enable_if_t
<
std
::
is_default_constructible
<
T
>::
value
>> =
nullptr
>
57
constexpr
ebo_holder
()
noexcept
(
std
::
is_nothrow_default_constructible
<
T
>::
value
)
58
:
value_
{} {}
59
60
ARENE_IGNORE_START
();
61
ARENE_IGNORE_ARMCLANG
(
"-Wimplicit-int-float-conversion"
,
"This type supports the same conversions as the Value"
);
62
/// @brief in-place constructor
63
/// @tparam Args types to construct from
64
/// @param args arguments to construct from
65
///
66
/// Constructs value from @c args.
67
template
<
68
class
...
Args
,
69
constraints
<
70
std
::
enable_if_t
<
std
::
is_constructible
<
Value
,
Args
&&...>::
value
>,
71
std
::
enable_if_t
<
//
72
!
std
::
is_same
<
//
73
type_list
<
ebo_holder
>,
74
type_list
<
remove_cvref_t
<
Args
>...>
//
75
>::
value
//
76
>
//
77
> =
nullptr
>
78
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
79
constexpr
explicit
ebo_holder
(
Args
&&...
args
)
noexcept
(
std
::
is_nothrow_constructible
<
Value
,
Args
&&...>::
value
)
80
:
value_
{
std
::
forward
<
Args
>(
args
)...} {}
81
ARENE_IGNORE_END
();
82
83
// parasoft-begin-suppress AUTOSAR-M9_3_1-a-2 "False positive: returns const handle"
84
// parasoft-begin-suppress AUTOSAR-A9_3_1-b-2 "False positive: returns const handle"
85
/// @brief Get the value
86
/// @return const value_type& A reference to the held value
87
constexpr
auto
get_value
(
Tag
)
const
&
noexcept
->
value_type
const
& {
return
value_
; }
88
// parasoft-end-suppress AUTOSAR-A9_3_1-b-2
89
// parasoft-end-suppress AUTOSAR-M9_3_1-a-2
90
91
/// @brief Get the value
92
/// @return value_type& A reference to the held value
93
// parasoft-begin-suppress AUTOSAR-A9_3_1-a "This class doesn't contain/own the data, it wraps it with type info"
94
// parasoft-begin-suppress AUTOSAR-A9_3_1-b "This class doesn't contain/own the data, it wraps it with type info"
95
constexpr
auto
get_value
(
Tag
) &
noexcept
->
value_type
& {
return
value_
; }
96
// parasoft-end-suppress AUTOSAR-A9_3_1-b
97
// parasoft-end-suppress AUTOSAR-A9_3_1-a
98
99
/// @brief Get the value
100
/// @return const value_type&& A reference to the held value
101
constexpr
auto
get_value
(
Tag
)
const
&&
noexcept
->
value_type
const
&& {
return
std
::
move
(
value_
); }
102
103
/// @brief Get the value
104
/// @return value_type&& A reference to the held value
105
constexpr
auto
get_value
(
Tag
) &&
noexcept
->
value_type
&& {
return
std
::
move
(
value_
); }
106
};
107
// parasoft-end-suppress AUTOSAR-A12_1_5-a
108
109
/// @brief A class to hold a value, making use of the empty base class optimization if possible. This specialization is
110
/// for types that can be used as a base class
111
///
112
/// @tparam Tag A tag type to indicate this instance, for classes that have multiple values to hold
113
/// @tparam Value The type of the value to hold
114
template
<
typename
Tag,
typename
Value>
115
class
ebo_holder
<
Tag
,
Value
,
true
> : Value {
116
public
:
117
// parasoft-begin-suppress AUTOSAR-A2_10_1-d "False positive: 'value_type' does not hide anything"
118
/// @brief The type held by the EBO holder.
119
using
value_type = Value;
120
// parasoft-end-suppress AUTOSAR-A2_10_1-d
121
122
// parasoft-begin-suppress AUTOSAR-A12_7_1-a "False positive: =default will have wrong semantics"
123
124
/// @brief default constructor
125
/// @tparam T template parameter used to check constraints
126
///
127
/// Default constructs the contained value.
128
template
<
class
T
=
Value
,
constraints
<
std
::
enable_if_t
<
std
::
is_default_constructible
<
T
>::
value
>> =
nullptr
>
129
constexpr
ebo_holder
()
noexcept
(
std
::
is_nothrow_default_constructible
<
T
>::
value
)
130
:
Value
{} {}
131
132
// parasoft-end-suppress AUTOSAR-A12_7_1-a
133
134
/// @brief in-place constructor
135
/// @tparam Args types to construct from
136
/// @param args arguments to construct from
137
///
138
/// Constructs value from @c args.
139
template
<
140
class
...
Args
,
141
constraints
<
142
std
::
enable_if_t
<
std
::
is_constructible
<
Value
,
Args
&&...>::
value
>,
143
std
::
enable_if_t
<
//
144
!
std
::
is_same
<
//
145
type_list
<
ebo_holder
>,
146
type_list
<
remove_cvref_t
<
Args
>...>
//
147
>::
value
//
148
>
//
149
> =
nullptr
>
150
// NOLINTNEXTLINE(bugprone-forwarding-reference-overload)
151
constexpr
explicit
ebo_holder
(
Args
&&...
args
)
noexcept
(
std
::
is_nothrow_constructible
<
Value
,
Args
&&...>::
value
)
152
:
Value
{
std
::
forward
<
Args
>(
args
)...} {}
153
154
/// @brief Get the value
155
/// @return const value_type& A reference to the held value
156
constexpr
auto
get_value
(
Tag
)
const
&
noexcept
->
value_type
const
& {
return
static_cast
<
value_type
const
&>(*
this
); }
157
/// @brief Get the value
158
/// @return value_type& A reference to the held value
159
constexpr
auto
get_value
(
Tag
) &
noexcept
->
value_type
& {
return
static_cast
<
value_type
&>(*
this
); }
160
/// @brief Get the value
161
/// @return const value_type&& A reference to the held value
162
constexpr
auto
get_value
(
Tag
)
const
&&
noexcept
->
value_type
const
&& {
163
return
static_cast
<
value_type
const
&&>(*
this
);
164
}
165
/// @brief Get the value
166
/// @return value_type&& A reference to the held value
167
constexpr
auto
get_value
(
Tag
) &&
noexcept
->
value_type
&& {
return
static_cast
<
value_type
&&>(*
this
); }
168
};
169
170
// parasoft-end-suppress AUTOSAR-A14_5_1-a
171
172
}
// namespace base
173
}
// namespace arene
174
175
// parasoft-end-suppress AUTOSAR-M2_10_1-a-2
176
177
#
endif
// INCLUDE_GUARD_ARENE_BASE_ARENE_BASE_TYPE_MANIPULATION_EBO_HOLDER_HPP_
arene::base::ebo_holder< Tag, Value, true >::ebo_holder
constexpr ebo_holder() noexcept(std::is_nothrow_default_constructible< T >::value)
default constructor
Definition
ebo_holder.hpp:129
arene::base
Definition
array_exceptions_disabled.cpp:11
arene
Copyright 2026, Toyota Motor Corporation.
Definition
array_exceptions_disabled.cpp:10
arene
base
type_manipulation
ebo_holder.hpp
Generated by
1.13.2