From 4698812fdc2d9eeea03f26307d6e7e626aaec12b Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 31 Jul 2024 00:27:41 +0200 Subject: More work on refs --- .bazelrc | 2 ++ asl/meta/types.hpp | 26 ++++++++++++++++++++++++-- asl/meta/types_tests.cpp | 20 ++++++++++---------- 3 files changed, 36 insertions(+), 12 deletions(-) diff --git a/.bazelrc b/.bazelrc index 8fa0ff2..356c0c2 100644 --- a/.bazelrc +++ b/.bazelrc @@ -3,3 +3,5 @@ build --cxxopt=-Wall build --cxxopt=-Wno-c++98-compat build --cxxopt=-Wno-c++98-compat-pedantic build --cxxopt=-Wno-pre-c++17-compat +build --cxxopt=-Wno-c++20-compat +build --cxxopt=-Wno-unused-macros diff --git a/asl/meta/types.hpp b/asl/meta/types.hpp index b5aa192..79ccf5e 100644 --- a/asl/meta/types.hpp +++ b/asl/meta/types.hpp @@ -5,10 +5,32 @@ namespace asl { template using void_t = void; template -inline constexpr bool referenceable = false; +inline constexpr bool is_referenceable = false; template -inline constexpr bool referenceable> = true; +inline constexpr bool is_referenceable> = true; + +namespace internal { + +template> +struct as_ref_helper { using lvalue = T; using rvalue = T; }; + +template +struct as_ref_helper { using lvalue = T&; using rvalue = T&&; }; + +template struct un_ref_helper { using type = T; }; +template struct un_ref_helper { using type = T; }; +template struct un_ref_helper { using type = T; }; + +} // namespace internal + +template using as_ref_t = internal::as_ref_helper::lvalue; +template using as_rref_t = internal::as_ref_helper::rvalue; + +template using un_ref_t = internal::un_ref_helper::type; + +#define AslMove(expr_) (static_cast<::asl::as_rref_t<::asl::un_ref_t>>(expr_)) +#define AslForward(expr_) (static_cast<::asl::as_rref_t>(expr_)) } // namespace asl diff --git a/asl/meta/types_tests.cpp b/asl/meta/types_tests.cpp index cab9118..2e3de25 100644 --- a/asl/meta/types_tests.cpp +++ b/asl/meta/types_tests.cpp @@ -2,15 +2,15 @@ using namespace asl; -static_assert(referenceable); -static_assert(referenceable); -static_assert(referenceable); -static_assert(!referenceable); -static_assert(referenceable); -static_assert(referenceable); -static_assert(referenceable); -static_assert(!referenceable); -static_assert(!referenceable); -static_assert(!referenceable); +static_assert(is_referenceable); +static_assert(is_referenceable); +static_assert(is_referenceable); +static_assert(!is_referenceable); +static_assert(is_referenceable); +static_assert(is_referenceable); +static_assert(is_referenceable); +static_assert(!is_referenceable); +static_assert(!is_referenceable); +static_assert(!is_referenceable); int main() { return 0; } -- cgit