From 0776012d0942537b1ddfef13cd37f8bfb125f501 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 1 Apr 2025 00:39:24 +0200 Subject: Add bit library --- asl/base/meta.hpp | 83 +++++++++++++++++++++++++++++++++++++++++++++++-------- 1 file changed, 72 insertions(+), 11 deletions(-) (limited to 'asl/base/meta.hpp') diff --git a/asl/base/meta.hpp b/asl/base/meta.hpp index 1d57367..c13439a 100644 --- a/asl/base/meta.hpp +++ b/asl/base/meta.hpp @@ -25,6 +25,9 @@ struct empty {}; template struct id { using type = T; }; +struct in_place_t {}; +static constexpr in_place_t in_place{}; + template static constexpr isize_t types_count = sizeof...(Args); template struct integral_constant { static constexpr T value = kValue; }; @@ -234,17 +237,75 @@ template<> struct _is_floating_point_helper : true_type {}; template concept is_floating_point = _is_floating_point_helper>::value; -template struct _is_integer_helper : false_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; -template<> struct _is_integer_helper : true_type {}; - -template concept is_integer = _is_integer_helper>::value; +template struct _integer_traits +{ + static constexpr bool kSigned = false; + static constexpr bool kUnsigned = false; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = false; + static constexpr bool kUnsigned = true; + using as_signed = int8_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = false; + static constexpr bool kUnsigned = true; + using as_signed = int16_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = false; + static constexpr bool kUnsigned = true; + using as_signed = int32_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = false; + static constexpr bool kUnsigned = true; + using as_signed = int64_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = true; + static constexpr bool kUnsigned = false; + using as_unsigned = uint8_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = true; + static constexpr bool kUnsigned = false; + using as_unsigned = uint16_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = true; + static constexpr bool kUnsigned = false; + using as_unsigned = uint32_t; +}; + +template<> struct _integer_traits +{ + static constexpr bool kSigned = true; + static constexpr bool kUnsigned = false; + using as_unsigned = uint64_t; +}; + +template concept is_signed_integer = _integer_traits::kSigned; +template concept is_unsigned_integer = _integer_traits::kUnsigned; + +template concept is_integer = is_signed_integer || is_unsigned_integer; + +template using as_unsigned_integer = _integer_traits::as_unsigned; +template using as_signed_integer = _integer_traits::as_signed; template concept is_enum = __is_enum(T); -- cgit