From 3ac99f1bd8664c781fdcee28d0e489973ac26003 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 8 Mar 2023 21:30:21 +0200 Subject: [PATCH] BAN: Add more traits and cleanup code --- BAN/include/BAN/Traits.h | 40 ++++++++++++++++++++++++++++++---------- 1 file changed, 30 insertions(+), 10 deletions(-) diff --git a/BAN/include/BAN/Traits.h b/BAN/include/BAN/Traits.h index 301338b7..d5ee04a9 100644 --- a/BAN/include/BAN/Traits.h +++ b/BAN/include/BAN/Traits.h @@ -12,6 +12,13 @@ namespace BAN template struct remove_const { using type = T; }; template using remove_const_t = typename remove_const::type; + template struct remove_volatile { using type = T; }; + template struct remove_volatile { using type = T; }; + template using remove_volatile_t = typename remove_volatile::type; + + template struct remove_cv { using type = remove_volatile_t>; }; + template using remove_cv_t = typename remove_cv::type; + template struct remove_const_and_reference { using type = remove_const_t>; }; template using remove_const_and_reference_t = typename remove_const_and_reference::type; @@ -19,24 +26,37 @@ namespace BAN template struct enable_if { using type = T; }; template using enable_if_t = typename enable_if::type; - template struct is_same { static constexpr bool value = false; }; - template struct is_same { static constexpr bool value = true; }; - template inline constexpr bool is_same_v = is_same::value; - - template struct is_lvalue_reference { static constexpr bool value = false; }; - template struct is_lvalue_reference { static constexpr bool value = true; }; - template inline constexpr bool is_lvalue_reference_v = is_lvalue_reference::value; - template struct maybe_const { using type = T; }; template struct maybe_const { using type = const T; }; template using maybe_const_t = typename maybe_const::type; + struct true_type { static constexpr bool value = true; }; + struct false_type { static constexpr bool value = false; }; + + template struct is_same : false_type {}; + template struct is_same : true_type {}; + template inline constexpr bool is_same_v = is_same::value; + + template struct is_lvalue_reference : false_type {}; + template struct is_lvalue_reference : true_type {}; + template inline constexpr bool is_lvalue_reference_v = is_lvalue_reference::value; + template struct is_integral { static constexpr bool value = requires (T t, T* p, void (*f)(T)) { reinterpret_cast(t); f(0); p + t; }; }; template inline constexpr bool is_integral_v = is_integral::value; template concept integral = is_integral_v; - template struct is_pointer { static constexpr bool value = false; }; - template struct is_pointer { static constexpr bool value = true; }; + template struct is_floating_point : false_type {}; + template<> struct is_floating_point : true_type {}; + template<> struct is_floating_point : true_type {}; + template<> struct is_floating_point : true_type {}; + template inline constexpr bool is_floating_point_v = is_floating_point::value; + template concept floating_point = is_floating_point_v; + + template struct is_pointer : false_type {}; + template struct is_pointer : true_type {}; + template struct is_pointer : true_type {}; + template struct is_pointer : true_type {}; + template struct is_pointer : true_type {}; template inline constexpr bool is_pointer_v = is_pointer::value; template concept pointer = is_pointer_v;