tetl 0.1.0
Embedded Template Library
Loading...
Searching...
No Matches
make_signed.hpp
Go to the documentation of this file.
1// SPDX-License-Identifier: BSL-1.0
2// SPDX-FileCopyrightText: Copyright (C) 2021 Tobias Hienzsch
3
4#ifndef TETL_TYPE_TRAITS_MAKE_SIGNED_HPP
5#define TETL_TYPE_TRAITS_MAKE_SIGNED_HPP
6
7namespace etl {
8
9namespace detail {
10
11template <typename>
12struct make_signed;
13
14template <>
15struct make_signed<signed char> {
16 using type = signed char;
17};
18
19template <>
20struct make_signed<signed short> {
21 using type = signed short;
22};
23
24template <>
25struct make_signed<signed int> {
26 using type = signed int;
27};
28
29template <>
30struct make_signed<signed long> {
31 using type = signed long;
32};
33
34template <>
35struct make_signed<signed long long> {
36 using type = signed long long;
37};
38
39template <>
40struct make_signed<unsigned char> {
41 using type = signed char;
42};
43
44template <>
45struct make_signed<unsigned short> {
46 using type = signed short;
47};
48
49template <>
50struct make_signed<unsigned int> {
51 using type = signed int;
52};
53
54template <>
55struct make_signed<unsigned long> {
56 using type = signed long;
57};
58
59template <>
60struct make_signed<unsigned long long> {
61 using type = signed long long;
62};
63
64} // namespace detail
65
66/// If T is an integral (except bool) or enumeration type, provides the
67/// member typedef type which is the unsigned integer type corresponding to T,
68/// with the same cv-qualifiers. If T is signed or unsigned char, short, int,
69/// long, long long; the unsigned type from this list corresponding to T is
70/// provided. The behavior of a program that adds specializations for
71/// make_signed is undefined.
72///
73/// \code
74/// // Convert an unsigned int to signed int
75/// static_assert(is_same_v<make_signed_t<unsigned>, int>);
76/// \endcode
77///
78/// \ingroup type_traits
79template <typename Type>
80struct make_signed : etl::detail::make_signed<Type> { };
81
82template <typename T>
83using make_signed_t = typename make_signed<T>::type;
84
85} // namespace etl
86
87#endif // TETL_TYPE_TRAITS_MAKE_SIGNED_HPP
Definition adjacent_find.hpp:9
If T is an integral (except bool) or enumeration type, provides the member typedef type which is the ...
Definition make_signed.hpp:80