bux API Reference 1.9.0
Static library of whatever are seen required in general purpose but not directly supported from Modern C++. Or whatever reusable originated from my side projects.
Loading...
Searching...
No Matches
Range2Type.h
Go to the documentation of this file.
1#pragma once
2
3#include "StrUtil.h" // HRTN()
4#include <concepts> // std::integral<>
5#include <limits> // std::numeric_limits<>
6#include <cstdint> // std::uint8_t, std::uint16_t, std::uint32_t
7
8namespace bux {
9
10//
11// Fnction Templates
12//
13template<std::integral T>
14std::string fittestType(T lb, T ub)
20{
21 if constexpr (std::numeric_limits<T>::is_signed)
22 {
23 if (std::numeric_limits<std::int8_t>::min() <= lb &&
24 ub <= std::numeric_limits<std::int8_t>::max())
25 return "int8_t";
26
27 if constexpr (sizeof(T) >= sizeof(std::int16_t))
28 {
29 if (std::numeric_limits<std::int16_t>::min() <= lb &&
30 ub <= std::numeric_limits<std::int16_t>::max())
31 return "int16_t";
32 }
33
34 if constexpr (sizeof(T) >= sizeof(std::int32_t))
35 {
36 if (std::numeric_limits<std::int32_t>::min() <= lb &&
37 ub <= std::numeric_limits<std::int32_t>::max())
38 return "int32_t";
39 }
40
41 // There could be more ..
42 }
43 else
44 {
45 if (ub <= (T)std::numeric_limits<std::uint8_t>::max())
46 return "uint8_t";
47
48 if constexpr (sizeof(T) >= sizeof(std::uint16_t))
49 {
50 if (ub <= (T)std::numeric_limits<std::uint16_t>::max())
51 return "uint16_t";
52 }
53
54 if constexpr (sizeof(T) >= sizeof(std::uint32_t))
55 {
56 if (ub <= (T)std::numeric_limits<std::uint32_t>::max())
57 return "uint32_t";
58 }
59
60 // There could be more ..
61 }
62 return HRTN(T);
63}
64
65} //namespace bux
#define HRTN(t)
Definition StrUtil.h:22
THE common namespace of bux library.
Definition AtomiX.cpp:3
std::string fittestType(T lb, T ub)
Definition Range2Type.h:14