diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-07-04 18:21:35 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2025-07-04 18:22:03 +0200 |
commit | cca2e267241a90f238e424e47501b1e8613a5955 (patch) | |
tree | 94ccb4edd115ecc3a5e1f94a34aade79285b91c0 | |
parent | 195f20ff1706b2ae9aeb3a991245dd23f692eeea (diff) |
Add integer traits
-rw-r--r-- | asl/base/integers.hpp | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/asl/base/integers.hpp b/asl/base/integers.hpp index 4580509..6bc4c34 100644 --- a/asl/base/integers.hpp +++ b/asl/base/integers.hpp @@ -40,5 +40,25 @@ namespace asl enum class byte : uint8_t {}; +template<typename T> struct integer_traits {}; + +#define ASL_INTEGER_TRAITS(T, MIN, MAX) \ + template<> struct integer_traits<T> \ + { \ + static constexpr T kMin = MIN; \ + static constexpr T kMax = MAX; \ + } + +ASL_INTEGER_TRAITS(uint8_t, 0, 0xff); +ASL_INTEGER_TRAITS(uint16_t, 0, 0xffff); +ASL_INTEGER_TRAITS(uint32_t, 0, 0xffff'ffff); +ASL_INTEGER_TRAITS(uint64_t, 0, 0xffff'ffff'ffff'ffff); +ASL_INTEGER_TRAITS(int8_t, -0x80, 0x7f); +ASL_INTEGER_TRAITS(int16_t, -0x8000, 0x7fff); +ASL_INTEGER_TRAITS(int32_t, -0x8000'0000, 0x7fff'ffff); +ASL_INTEGER_TRAITS(int64_t, -0x8000'0000'0000'0000, 0x7fff'ffff'ffff'ffff); + +#undef ASL_INTEGER_TRAITS + } // namespace asl |