From 75b10758ba116eabed730d23e957f1d69a1e3cb8 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Tue, 6 Aug 2024 00:34:57 +0200 Subject: Type traits --- asl/meta.hpp | 89 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 89 insertions(+) create mode 100644 asl/meta.hpp (limited to 'asl/meta.hpp') diff --git a/asl/meta.hpp b/asl/meta.hpp new file mode 100644 index 0000000..15f7790 --- /dev/null +++ b/asl/meta.hpp @@ -0,0 +1,89 @@ +#pragma once + +namespace asl { + +template struct integral_constant { static constexpr T value = kValue; }; +template using bool_constant = integral_constant; + +using true_type = bool_constant; +using false_type = bool_constant; + +using nullptr_t = decltype(nullptr); + +template struct un_ref { using type = T; }; +template struct un_ref { using type = T; }; +template struct un_ref { using type = T; }; +template using un_ref_t = un_ref::type; + +template struct un_const { using type = T; }; +template struct un_const { using type = T; }; +template using un_const_t = un_const::type; + +template struct un_volatile { using type = T; }; +template struct un_volatile { using type = T; }; +template using un_volatile_t = un_volatile::type; + +template using un_qual_t = un_const_t>; + +template using un_qualref_t = un_qual_t>; + +template struct _is_same_helper : false_type {}; +template struct _is_same_helper : true_type {}; + +template +concept is_same = _is_same_helper::value && _is_same_helper::value; + +template struct _is_const_helper : false_type {}; +template struct _is_const_helper : true_type {}; + +template concept is_const = _is_const_helper::value; + +template concept is_void = is_same, void>; +template concept is_nullptr = is_same, nullptr_t>; + +template concept is_integral = __is_integral(T); +template concept is_floating_point = __is_floating_point(T); +template concept is_arithmetic = is_integral || is_floating_point; + +template struct _is_array_helper : false_type {}; +template struct _is_array_helper : true_type {}; +template struct _is_array_helper : true_type {}; + +template concept is_array = _is_array_helper::value; + +template concept is_class = __is_class(T); +template concept is_union = __is_union(T); + +template concept is_enum = __is_enum(T); + +template struct _is_ptr_helper : false_type {}; +template struct _is_ptr_helper : true_type {}; + +template concept is_ptr = _is_ptr_helper>::value; + +template struct _is_ref_helper { static constexpr bool lref = false; static constexpr bool rref = false; }; +template struct _is_ref_helper { static constexpr bool lref = true; static constexpr bool rref = false; }; +template struct _is_ref_helper { static constexpr bool lref = false; static constexpr bool rref = true; }; + +template concept is_lref = _is_ref_helper::lref; +template concept is_rref = _is_ref_helper::rref; +template concept is_ref = is_lref || is_rref; + +template concept is_func = !is_const && !is_ref; + +template struct _is_member_ptr_helper : false_type {}; +template struct _is_member_ptr_helper : true_type {}; + +template struct _is_member_func_ptr_helper : false_type {}; +template struct _is_member_func_ptr_helper : bool_constant> {}; + +template concept is_member_ptr = _is_member_ptr_helper>::value; +template concept is_member_func_ptr = _is_member_func_ptr_helper>::value; +template concept is_member_object_ptr = is_member_ptr && !is_member_func_ptr; + +template concept is_fundamental = is_arithmetic || is_void || is_nullptr; +template concept is_compound = !is_fundamental; +template concept is_scalar = (is_fundamental && !is_void) || is_enum || is_ptr || is_member_ptr; +template concept is_object = is_scalar || is_array || is_class || is_union; + +} // namespace asl -- cgit