Wider.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Louis Langholtz https://github.com/louis-langholtz/PlayRho
3  *
4  * This software is provided 'as-is', without any express or implied
5  * warranty. In no event will the authors be held liable for any damages
6  * arising from the use of this software.
7  *
8  * Permission is granted to anyone to use this software for any purpose,
9  * including commercial applications, and to alter it and redistribute it
10  * freely, subject to the following restrictions:
11  *
12  * 1. The origin of this software must not be misrepresented; you must not
13  * claim that you wrote the original software. If you use this software
14  * in a product, an acknowledgment in the product documentation would be
15  * appreciated but is not required.
16  * 2. Altered source versions must be plainly marked as such, and must not be
17  * misrepresented as being the original software.
18  * 3. This notice may not be removed or altered from any source distribution.
19  */
20 
21 #ifndef PLAYRHO_COMMON_WIDER_HPP
22 #define PLAYRHO_COMMON_WIDER_HPP
23 
24 #include <PlayRho/Defines.hpp>
25 #include <cstdint>
26 #include <type_traits>
27 
28 // clang-format off
29 
30 namespace playrho
31 {
32 
37 template <typename T> struct Wider {};
38 
40 template <> struct Wider<std::int8_t> {
41  using type = std::int16_t;
42 };
43 
45 template <> struct Wider<std::uint8_t> {
46  using type = std::uint16_t;
47 };
48 
50 template <> struct Wider<std::int16_t> {
51  using type = std::int32_t;
52 };
53 
55 template <> struct Wider<std::uint16_t> {
56  using type = std::uint32_t;
57 };
58 
60 template <> struct Wider<std::int32_t> {
61  using type = std::int64_t;
62 };
63 
65 template <> struct Wider<std::uint32_t> {
66  using type = std::uint64_t;
67 };
68 
70 template <> struct Wider<float> {
71  using type = double;
72 };
73 
75 template <> struct Wider<double> {
76  using type = long double;
77 };
78 
79 #ifdef PLAYRHO_INT128
80 template <> struct Wider<std::int64_t> {
82  using type = PLAYRHO_INT128;
83 };
84 #endif
85 
86 #ifdef PLAYRHO_UINT128
87 template <> struct Wider<std::uint64_t> {
89  using type = PLAYRHO_UINT128;
90 };
91 #endif
92 
93 } // namespace playrho
94 
95 namespace std {
96 
97 #if defined(PLAYRHO_INT128) && defined(PLAYRHO_UINT128)
98 // This might already be defined by the standard library header, but
99 // define it here explicitly in case it's not.
100 
102 template <> struct make_unsigned<PLAYRHO_INT128> {
103  using type = PLAYRHO_UINT128;
104 };
105 #endif
106 
107 } // namespace std
108 
109 // clang-format on
110 
111 #endif // PLAYRHO_COMMON_WIDER_HPP