Arene Base
Fundamental Utilities For Safety Critical C++
Loading...
Searching...
No Matches
make_unsigned.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_STDLIB_INCLUDE_STDLIB_DETAIL_MAKE_UNSIGNED_HPP_
6
#
define
INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAKE_UNSIGNED_HPP_
7
8
// parasoft-begin-suppress CERT_CPP-DCL58-a-2 "Part of a standard library implementation"
9
// parasoft-begin-suppress AUTOSAR-A17_6_1-a-2 "Part of a standard library implementation"
10
11
// IWYU pragma: private, include <type_traits>
12
// IWYU pragma: friend "stdlib_detail/.*"
13
14
#
include
"arene/base/constraints.hpp"
15
#
include
"stdlib/include/stdlib_detail/add_const.hpp"
16
#
include
"stdlib/include/stdlib_detail/add_volatile.hpp"
17
#
include
"stdlib/include/stdlib_detail/conditional.hpp"
18
#
include
"stdlib/include/stdlib_detail/cstdint.hpp"
19
#
include
"stdlib/include/stdlib_detail/enable_if.hpp"
20
#
include
"stdlib/include/stdlib_detail/is_const.hpp"
21
#
include
"stdlib/include/stdlib_detail/is_enum.hpp"
22
#
include
"stdlib/include/stdlib_detail/is_integral.hpp"
23
#
include
"stdlib/include/stdlib_detail/is_same.hpp"
24
#
include
"stdlib/include/stdlib_detail/is_signed.hpp"
25
#
include
"stdlib/include/stdlib_detail/is_volatile.hpp"
26
#
include
"stdlib/include/stdlib_detail/remove_cv.hpp"
27
28
namespace
std
{
29
30
// parasoft-begin-suppress AUTOSAR-A2_7_3-a "False positive: all declarations
31
// and typedefs *are* preceded by a comment with @brief"
32
33
namespace
make_unsigned_detail
{
34
/// @brief Internal class providing @c std::make_unsigned
35
/// @tparam Type The type to convert to an unsigned equivalent
36
// parasoft-begin-suppress AUTOSAR-A11_0_2 "False positive: Not used as a base class here"
37
template
<
typename
Type,
typename
=
arene
::
base
::
constraints
<>>
38
struct
make_unsigned
{};
39
// parasoft-end-suppress AUTOSAR-A11_0_2
40
41
/// @brief Internal class providing @c std::make_unsigned for integral types that are already unsigned
42
/// @tparam Type The type to convert to an unsigned equivalent
43
template
<
typename
Type
>
44
struct
make_unsigned
<
45
Type
,
46
arene
::
base
::
constraints
<
47
enable_if_t
<
is_integral_v
<
Type
>>,
48
enable_if_t
<!
is_signed_v
<
Type
>>,
49
enable_if_t
<!
is_same_v
<
Type
,
bool
>>,
50
enable_if_t
<!
is_const_v
<
Type
>>,
51
enable_if_t
<!
is_volatile_v
<
Type
>>>> {
52
/// @brief The resulting type
53
using
type
=
Type
;
54
};
55
56
/// @brief Internal class providing @c std::make_unsigned for integral types or enumeration types that are @c const
57
/// qualified
58
/// @tparam Type The type to convert to an unsigned equivalent
59
template
<
typename
Type
>
60
struct
make_unsigned
<
61
Type
,
62
arene
::
base
::
constraints
<
63
enable_if_t
<
is_integral_v
<
Type
> ||
is_enum_v
<
Type
>>,
64
enable_if_t
<
is_const_v
<
Type
>>,
65
enable_if_t
<!
is_volatile_v
<
Type
>>>> {
66
/// @brief The resulting type
67
using
type
=
add_const_t
<
typename
make_unsigned
<
remove_cv_t
<
Type
>>::
type
>;
68
};
69
70
/// @brief Internal class providing @c std::make_unsigned for integral types or enumeration types that are @c volatile
71
/// qualified
72
/// @tparam Type The type to convert to an unsigned equivalent
73
template
<
typename
Type
>
74
struct
make_unsigned
<
75
Type
,
76
arene
::
base
::
constraints
<
77
enable_if_t
<
is_integral_v
<
Type
> ||
is_enum_v
<
Type
>>,
78
enable_if_t
<
is_volatile_v
<
Type
>>,
79
enable_if_t
<!
is_const_v
<
Type
>>>> {
80
/// @brief The resulting type
81
using
type
=
add_volatile_t
<
typename
make_unsigned
<
remove_cv_t
<
Type
>>::
type
>;
82
};
83
84
/// @brief Internal class providing @c std::make_unsigned for integral types or enumeration types that are @c const
85
/// and @c volatile qualified
86
/// @tparam Type The type to convert to an unsigned equivalent
87
template
<
typename
Type
>
88
struct
make_unsigned
<
89
Type
,
90
arene
::
base
::
constraints
<
91
enable_if_t
<
is_integral_v
<
Type
> ||
is_enum_v
<
Type
>>,
92
enable_if_t
<
is_const_v
<
Type
>>,
93
enable_if_t
<
is_volatile_v
<
Type
>>>> {
94
/// @brief The resulting type
95
using
type
=
add_const_t
<
add_volatile_t
<
typename
make_unsigned
<
remove_cv_t
<
Type
>>::
type
>>;
96
};
97
98
// parasoft-begin-suppress AUTOSAR-A3_9_1-b-2 "The built-in types must be handled explicitly here for correctness"
99
/// @brief Internal class providing @c std::make_unsigned for @c signed char
100
template
<>
101
struct
make_unsigned
<
signed
char
> {
102
/// @brief The resulting type
103
using
type
=
unsigned
char
;
104
};
105
106
/// @brief Internal class providing @c std::make_unsigned for @c short
107
template
<>
108
// NOLINTNEXTLINE(google-runtime-int)
109
struct
make_unsigned
<
short
> {
110
/// @brief The resulting type
111
// NOLINTNEXTLINE(google-runtime-int)
112
using
type
=
unsigned
short
;
113
};
114
115
/// @brief Internal class providing @c std::make_unsigned for @c int
116
template
<>
117
struct
make_unsigned
<
int
> {
118
/// @brief The resulting type
119
using
type
=
unsigned
;
120
};
121
122
/// @brief Internal class providing @c std::make_unsigned for @c long
123
template
<>
124
// NOLINTNEXTLINE(google-runtime-int)
125
struct
make_unsigned
<
long
> {
126
/// @brief The resulting type
127
// NOLINTNEXTLINE(google-runtime-int)
128
using
type
=
unsigned
long
;
129
};
130
131
/// @brief Internal class providing @c std::make_unsigned for @c long @c long
132
template
<>
133
// NOLINTNEXTLINE(google-runtime-int)
134
struct
make_unsigned
<
long
long
> {
135
/// @brief The resulting type
136
// NOLINTNEXTLINE(google-runtime-int)
137
using
type
=
unsigned
long
long
;
138
};
139
140
/// @brief Internal class providing @c std::make_unsigned for @c char
141
template
<>
142
struct
make_unsigned
<
char
> {
143
/// @brief The resulting type
144
// NOLINTNEXTLINE(google-runtime-int)
145
using
type
=
conditional_t
<
is_signed_v
<
char
>,
unsigned
char
,
char
>;
146
};
147
148
/// @brief Internal class providing an unsigned type with a specified size
149
/// @tparam Size the size to check
150
template
<size_t Size,
typename
=
arene
::
base
::
constraints
<>>
151
struct
sized_unsigned
{};
152
153
/// @brief Internal class providing an unsigned type with the size of @c char
154
/// @tparam Size the size to check
155
template
<
size_t
Size
>
156
struct
sized_unsigned
<
Size
,
arene
::
base
::
constraints
<
enable_if_t
<
Size
==
sizeof
(
char
)>>> {
157
/// @brief The resulting type
158
using
type
=
unsigned
char
;
159
};
160
161
/// @brief Internal class providing an unsigned type with the size of @c short
162
/// @tparam Size the size to check
163
template
<
size_t
Size
>
164
// NOLINTNEXTLINE(google-runtime-int)
165
struct
sized_unsigned
<
Size
,
arene
::
base
::
constraints
<
enable_if_t
<
Size
==
sizeof
(
short
)>>> {
166
/// @brief The resulting type
167
// NOLINTNEXTLINE(google-runtime-int)
168
using
type
=
unsigned
short
;
169
};
170
171
/// @brief Internal class providing an unsigned type with the size of @c int
172
/// @tparam Size the size to check
173
template
<
size_t
Size
>
174
struct
sized_unsigned
<
175
Size
,
176
// NOLINTNEXTLINE(google-runtime-int)
177
arene
::
base
::
constraints
<
enable_if_t
<(
Size
>
sizeof
(
short
))>,
enable_if_t
<
Size
==
sizeof
(
int
)>>> {
178
/// @brief The resulting type
179
using
type
=
unsigned
;
180
};
181
182
/// @brief Internal class providing an unsigned type with the size of @c long
183
/// @tparam Size the size to check
184
template
<
size_t
Size
>
185
struct
sized_unsigned
<
186
Size
,
187
// NOLINTNEXTLINE(google-runtime-int)
188
arene
::
base
::
constraints
<
enable_if_t
<(
Size
>
sizeof
(
int
))>,
enable_if_t
<
Size
==
sizeof
(
long
)>>> {
189
/// @brief The resulting type
190
// NOLINTNEXTLINE(google-runtime-int)
191
using
type
=
unsigned
long
;
192
};
193
194
/// @brief Internal class providing an unsigned type with the size of @c long long
195
/// @tparam Size the size to check
196
template
<
size_t
Size
>
197
struct
sized_unsigned
<
198
Size
,
199
// NOLINTNEXTLINE(google-runtime-int)
200
arene
::
base
::
constraints
<
enable_if_t
<(
Size
>
sizeof
(
long
))>,
enable_if_t
<
Size
==
sizeof
(
long
long
)>>> {
201
/// @brief The resulting type
202
// NOLINTNEXTLINE(google-runtime-int)
203
using
type
=
unsigned
long
long
;
204
};
205
// parasoft-end-suppress AUTOSAR-A3_9_1-b-2
206
207
// parasoft-begin-suppress AUTOSAR-A2_13_3-a-2 "wchar_t must be used here to ensure correctness"
208
/// @brief Internal class providing an unsigned type for @c wchar_t
209
template
<>
210
struct
make_unsigned
<
wchar_t
> {
211
/// @brief The resulting type
212
// NOLINTNEXTLINE(google-runtime-int)
213
using
type
=
typename
sized_unsigned
<
sizeof
(
wchar_t
)>::
type
;
214
};
215
// parasoft-end-suppress AUTOSAR-A2_13_3-a-2
216
217
/// @brief Internal class providing an unsigned type for @c char16_t
218
template
<>
219
struct
make_unsigned
<
char16_t
> {
220
/// @brief The resulting type
221
using
type
=
typename
sized_unsigned
<
sizeof
(
char16_t
)>::
type
;
222
};
223
224
/// @brief Internal class providing an unsigned type for @c char32_t
225
template
<>
226
struct
make_unsigned
<
char32_t
> {
227
/// @brief The resulting type
228
using
type
=
typename
sized_unsigned
<
sizeof
(
char32_t
)>::
type
;
229
};
230
231
/// @brief Internal class providing @c std::make_unsigned for integral types that are already unsigned
232
/// @tparam Type The type to convert to an unsigned equivalent
233
template
<
typename
Type
>
234
struct
make_unsigned
<
235
Type
,
236
arene
::
base
::
237
constraints
<
enable_if_t
<
is_enum_v
<
Type
>>,
enable_if_t
<!
is_const_v
<
Type
>>,
enable_if_t
<!
is_volatile_v
<
Type
>>>> {
238
/// @brief The resulting type
239
using
type
=
typename
sized_unsigned
<
sizeof
(
Type
)>::
type
;
240
};
241
242
}
// namespace make_unsigned_detail
243
244
/// @brief A type trait to provide the equivalent unsigned type for integral and enumeration types other than @c bool
245
/// @tparam Type The type to get the equivalent of
246
template
<
typename
Type
>
247
using
make_unsigned
=
make_unsigned_detail
::
make_unsigned
<
Type
>;
248
249
/// @brief A type alias for the equivalent unsigned type for integral and enumeration types other than @c bool
250
/// @tparam Type The type to get the equivalent of
251
template
<
typename
Type
>
252
using
make_unsigned_t
=
typename
make_unsigned
<
Type
>::
type
;
253
254
// parasoft-end-suppress AUTOSAR-A2_7_3-a
255
256
}
// namespace std
257
258
#
endif
// INCLUDE_GUARD_ARENE_BASE_STDLIB_INCLUDE_STDLIB_DETAIL_MAKE_UNSIGNED_HPP_
std::make_unsigned_detail
Definition
make_unsigned.hpp:33
std::hash<::arene::base::result< void, E > >::operator()
constexpr auto operator()(::arene::base::result< void, E > const &value) const noexcept(noexcept(hash< E >{}(std::declval< E const & >()))) -> std::size_t
Calculate the hash of a result.
Definition
result.hpp:1827
std::make_unsigned_detail::make_unsigned
Internal class providing std::make_unsigned.
Definition
make_unsigned.hpp:38
std::make_unsigned_detail::sized_unsigned
Internal class providing an unsigned type with a specified size.
Definition
make_unsigned.hpp:151
stdlib
include
stdlib_detail
make_unsigned.hpp
Generated by
1.13.2