From 4faa662a59fb5fdb0cad61e256dc3b0eeb1a2409 Mon Sep 17 00:00:00 2001 From: Bananymous Date: Wed, 1 Feb 2023 20:05:34 +0200 Subject: [PATCH] BAN: Rewrite Traits and add some more of them --- BAN/include/BAN/Move.h | 10 +++--- BAN/include/BAN/Traits.h | 73 +++++++++++++++++++++++++--------------- 2 files changed, 50 insertions(+), 33 deletions(-) diff --git a/BAN/include/BAN/Move.h b/BAN/include/BAN/Move.h index fb731b03..1890f0c5 100644 --- a/BAN/include/BAN/Move.h +++ b/BAN/include/BAN/Move.h @@ -6,21 +6,21 @@ namespace BAN { template - constexpr typename RemoveReference::type&& Move(T&& arg) + constexpr remove_reference_t&& Move(T&& arg) { - return static_cast::type&&>(arg); + return static_cast&&>(arg); } template - constexpr T&& Forward(typename RemoveReference::type& arg) + constexpr T&& Forward(remove_reference_t& arg) { return static_cast(arg); } template - constexpr T&& Forward(typename RemoveReference::type&& arg) + constexpr T&& Forward(remove_reference_t&& arg) { - static_assert(!IsLValueReference::value); + static_assert(!is_lvalue_reference_v); return static_cast(arg); } diff --git a/BAN/include/BAN/Traits.h b/BAN/include/BAN/Traits.h index 28e87fea..4ca18cda 100644 --- a/BAN/include/BAN/Traits.h +++ b/BAN/include/BAN/Traits.h @@ -3,39 +3,56 @@ namespace BAN { - template - struct RemoveReference { using type = T; }; - template - struct RemoveReference { using type = T; }; - template - struct RemoveReference { using type = T; }; + template struct remove_refenrece { using type = T; }; + template struct remove_refenrece { using type = T; }; + template struct remove_refenrece { using type = T; }; + template using remove_reference_t = typename remove_refenrece::type; - template - struct RemoveConst { using type = T; }; - template - struct RemoveConst { using type = T; }; + template struct remove_const { using type = T; }; + template struct remove_const { using type = T; }; + template using remove_const_t = typename remove_const::type; - template - struct EnableIf {}; - template - struct EnableIf { using type = T; }; + template struct remove_const_and_reference { using type = remove_const_t>; }; + template using remove_const_and_reference_t = typename remove_const_and_reference::type; - template - struct IsSame { static constexpr bool value = false; }; - template - struct IsSame { static constexpr bool value = true; }; + template struct enable_if {}; + template struct enable_if { using type = T; }; + template using enable_if_t = typename enable_if::type; - template - struct IsLValueReference { static constexpr bool value = false; }; - template - struct IsLValueReference { static constexpr bool value = true; }; + 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 Less { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs < rhs; } }; - template - struct Equal { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs == rhs; } }; - template - struct Greater { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs > rhs; } }; + template struct is_integral { static constexpr bool value = + is_same_v, bool> + || is_same_v, char> + || is_same_v, short> + || is_same_v, int> + || is_same_v, long> + || is_same_v, long long> + || is_same_v, signed char> + || is_same_v, signed short> + || is_same_v, signed int> + || is_same_v, signed long> + || is_same_v, signed long long> + || is_same_v, unsigned char> + || is_same_v, unsigned short> + || is_same_v, unsigned int> + || is_same_v, unsigned long> + || is_same_v, unsigned long long>; + }; + template inline constexpr bool is_integral_v = is_integral::value; + + template struct is_pointer { static constexpr bool value = false; }; + template struct is_pointer { static constexpr bool value = true; }; + template inline constexpr bool is_pointer_v = is_pointer::value; + + template struct less { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs < rhs; } }; + template struct equal { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs == rhs; } }; + template struct greater { constexpr bool operator()(const T& lhs, const T& rhs) const { return lhs > rhs; } }; } \ No newline at end of file