Shamrock 2025.10.0
Astrophysical Code
Loading...
Searching...
No Matches
primitive_type_info.hpp
Go to the documentation of this file.
1// -------------------------------------------------------//
2//
3// SHAMROCK code for hydrodynamics
4// Copyright (c) 2021-2026 Timothée David--Cléris <tim.shamrock@proton.me>
5// SPDX-License-Identifier: CeCILL Free Software License Agreement v2.1
6// Shamrock is licensed under the CeCILL 2.1 License, see LICENSE for more information
7//
8// -------------------------------------------------------//
9
10#pragma once
11
21#include <limits>
22
23namespace shambase {
24
25#if defined(DOXYGEN)
31 template<class _T>
34 using T = _T;
35
37 static constexpr bool is_specialized = false;
38
40 static constexpr bool is_float = false;
41
43 static constexpr bool is_int = false;
44
46 static constexpr bool is_unsigned = false;
47
49 static constexpr T max = std::numeric_limits<T>::max();
50
52 static constexpr T min = std::numeric_limits<T>::lowest();
53
55 static constexpr T epsilon = std::numeric_limits<T>::epsilon();
56
58 static constexpr T infty = std::numeric_limits<T>::infinity();
59 };
60#else
61
62 template<class T>
63 struct primitive_type_info {
64 static constexpr bool is_specialized = false;
65 static constexpr bool is_float = false;
66 static constexpr bool is_int = false;
67 static constexpr bool is_unsigned = false;
68 };
69
70 template<typename _T>
71 struct primitive_type_info<const _T> : public primitive_type_info<_T> {};
72
73 template<>
74 struct primitive_type_info<f64> {
75 using T = f64;
76
77 static constexpr bool is_specialized = true;
78 static constexpr bool is_float = true;
79 static constexpr bool is_int = false;
80 static constexpr bool is_unsigned = false;
81
82 static constexpr T max = std::numeric_limits<T>::max();
83 static constexpr T min = std::numeric_limits<T>::lowest();
84 static constexpr T epsilon = std::numeric_limits<T>::epsilon();
85 static constexpr T infty = std::numeric_limits<T>::infinity();
86 };
87
88 template<>
89 struct primitive_type_info<f32> {
90 using T = f32;
91
92 static constexpr bool is_specialized = true;
93 static constexpr bool is_float = true;
94 static constexpr bool is_int = false;
95 static constexpr bool is_unsigned = false;
96
97 static constexpr T max = std::numeric_limits<T>::max();
98 static constexpr T min = std::numeric_limits<T>::lowest();
99 static constexpr T epsilon = std::numeric_limits<T>::epsilon();
100 static constexpr T infty = std::numeric_limits<T>::infinity();
101 };
102
103 template<>
104 struct primitive_type_info<i8> {
105 using T = i8;
106
107 static constexpr bool is_specialized = true;
108 static constexpr bool is_float = false;
109 static constexpr bool is_int = true;
110 static constexpr bool is_unsigned = false;
111
112 static constexpr T max = std::numeric_limits<T>::max();
113 static constexpr T min = std::numeric_limits<T>::lowest();
114 };
115
116 template<>
117 struct primitive_type_info<i16> {
118 using T = i16;
119
120 static constexpr bool is_specialized = true;
121 static constexpr bool is_float = false;
122 static constexpr bool is_int = true;
123 static constexpr bool is_unsigned = false;
124
125 static constexpr T max = std::numeric_limits<T>::max();
126 static constexpr T min = std::numeric_limits<T>::lowest();
127 };
128
129 template<>
130 struct primitive_type_info<i32> {
131 using T = i32;
132
133 static constexpr bool is_specialized = true;
134 static constexpr bool is_float = false;
135 static constexpr bool is_int = true;
136 static constexpr bool is_unsigned = false;
137
138 static constexpr T max = std::numeric_limits<T>::max();
139 static constexpr T min = std::numeric_limits<T>::lowest();
140 };
141
142 template<>
143 struct primitive_type_info<i64> {
144 using T = i64;
145
146 static constexpr bool is_specialized = true;
147 static constexpr bool is_float = false;
148 static constexpr bool is_int = true;
149 static constexpr bool is_unsigned = false;
150
151 static constexpr T max = std::numeric_limits<T>::max();
152 static constexpr T min = std::numeric_limits<T>::lowest();
153 };
154 template<>
155 struct primitive_type_info<u8> {
156 using T = u8;
157
158 static constexpr bool is_specialized = true;
159 static constexpr bool is_float = false;
160 static constexpr bool is_int = true;
161 static constexpr bool is_unsigned = true;
162
163 static constexpr T max = std::numeric_limits<T>::max();
164 static constexpr T min = std::numeric_limits<T>::lowest();
165 };
166
167 template<>
168 struct primitive_type_info<u16> {
169 using T = u16;
170
171 static constexpr bool is_specialized = true;
172 static constexpr bool is_float = false;
173 static constexpr bool is_int = true;
174 static constexpr bool is_unsigned = true;
175
176 static constexpr T max = std::numeric_limits<T>::max();
177 static constexpr T min = std::numeric_limits<T>::lowest();
178 };
179
180 template<>
181 struct primitive_type_info<u32> {
182 using T = u32;
183
184 static constexpr bool is_specialized = true;
185 static constexpr bool is_float = false;
186 static constexpr bool is_int = true;
187 static constexpr bool is_unsigned = true;
188
189 static constexpr T max = std::numeric_limits<T>::max();
190 static constexpr T min = std::numeric_limits<T>::lowest();
191 };
192
193 template<>
194 struct primitive_type_info<u64> {
195 using T = u64;
196
197 static constexpr bool is_specialized = true;
198 static constexpr bool is_float = false;
199 static constexpr bool is_int = true;
200 static constexpr bool is_unsigned = true;
201
202 static constexpr T max = std::numeric_limits<T>::max();
203 static constexpr T min = std::numeric_limits<T>::lowest();
204 };
205#endif
206
207} // namespace shambase
double f64
Alias for double.
float f32
Alias for float.
std::int8_t i8
8 bit integer
std::uint8_t u8
8 bit unsigned integer
std::uint32_t u32
32 bit unsigned integer
std::uint64_t u64
64 bit unsigned integer
std::uint16_t u16
16 bit unsigned integer
std::int16_t i16
16 bit integer
std::int64_t i64
64 bit integer
std::int32_t i32
32 bit integer
namespace for basic c++ utilities
void throw_with_loc(std::string message, SourceLocation loc=SourceLocation{})
Throw an exception and append the source location to it.
Struct containing information about primitive types.
static constexpr T infty
Infinity if the type can represent it.
static constexpr bool is_unsigned
Whether the type is an unsigned integer type.
_T T
The type of the primitive type.
static constexpr bool is_float
Whether the type is a float type.
static constexpr bool is_int
Whether the type is an integer type.
static constexpr T min
The minimum value of the type (negative if float)
static constexpr T epsilon
The smallest value of the type that can be represented exactly.
static constexpr bool is_specialized
Whether the type is a specialized primitive type (i.e. not a float)
static constexpr T max
The maximum value of the type.