1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
#ifndef NUMPY_CORE_SRC_COMMON_META_HPP
#define NUMPY_CORE_SRC_COMMON_META_HPP
#include "npstd.hpp"
namespace np { namespace meta {
/// @addtogroup cpp_core_meta
/// @{
namespace details {
template<int size, bool unsig>
struct IntBySize;
template<bool unsig>
struct IntBySize<sizeof(uint8_t), unsig> {
using Type = typename std::conditional<
unsig, uint8_t, int8_t>::type;
};
template<bool unsig>
struct IntBySize<sizeof(uint16_t), unsig> {
using Type = typename std::conditional<
unsig, uint16_t, int16_t>::type;
};
template<bool unsig>
struct IntBySize<sizeof(uint32_t), unsig> {
using Type = typename std::conditional<
unsig, uint32_t, int32_t>::type;
};
template<bool unsig>
struct IntBySize<sizeof(uint64_t), unsig> {
using Type = typename std::conditional<
unsig, uint64_t, int64_t>::type;
};
} // namespace details
/// Provides safe conversion of any integer type synonyms
/// to a fixed-width integer type.
template<typename T>
struct FixedWidth {
using TF_ = typename details::IntBySize<
sizeof(T), std::is_unsigned<T>::value
>::Type;
using Type = typename std::conditional<
std::is_integral<T>::value, TF_, T
>::type;
};
/// @} cpp_core_meta
}} // namespace np::meta
#endif // NUMPY_CORE_SRC_COMMON_META_HPP
|