From 4228e82740f62b841799cfca04861fa217fb93a5 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 1 Aug 2024 00:56:05 +0200 Subject: More work on taxonomy --- asl/memory/BUILD.bazel | 10 +++++++++ asl/memory/layout.hpp | 6 ++++++ asl/meta/BUILD.bazel | 17 +++++++++++---- asl/meta/empty.hpp | 11 ++++++++++ asl/meta/empty_tests.cpp | 17 +++++++++++++++ asl/meta/funcs.hpp | 11 ++++++++++ asl/meta/funcs_tests.cpp | 14 +++++++++++++ asl/meta/internal/quals.hpp | 16 ++++++++++++++ asl/meta/internal/refs.hpp | 45 +++++++++++++++++++++++++++++++++++++++ asl/meta/internal/types.hpp | 9 ++++++++ asl/meta/quals.hpp | 22 +++++++++++++++++++ asl/meta/quals_tests.cpp | 51 +++++++++++++++++++++++++++++++++++++++++++++ asl/meta/refs.hpp | 21 +++++++++++++++++++ asl/meta/refs_tests.cpp | 33 +++++++++++++++++++++++++++++ asl/meta/types.hpp | 33 +++++------------------------ asl/meta/types_tests.cpp | 14 ++++--------- 16 files changed, 288 insertions(+), 42 deletions(-) create mode 100644 asl/memory/BUILD.bazel create mode 100644 asl/memory/layout.hpp create mode 100644 asl/meta/empty.hpp create mode 100644 asl/meta/empty_tests.cpp create mode 100644 asl/meta/funcs.hpp create mode 100644 asl/meta/funcs_tests.cpp create mode 100644 asl/meta/internal/quals.hpp create mode 100644 asl/meta/internal/refs.hpp create mode 100644 asl/meta/internal/types.hpp create mode 100644 asl/meta/quals.hpp create mode 100644 asl/meta/quals_tests.cpp create mode 100644 asl/meta/refs.hpp create mode 100644 asl/meta/refs_tests.cpp (limited to 'asl') diff --git a/asl/memory/BUILD.bazel b/asl/memory/BUILD.bazel new file mode 100644 index 0000000..7029496 --- /dev/null +++ b/asl/memory/BUILD.bazel @@ -0,0 +1,10 @@ +cc_library( + name = "memory", + hdrs = [ + "layout.hpp", + ], + deps = [ + "//asl/base", + ], + visibility = ["//visibility:public"], +) diff --git a/asl/memory/layout.hpp b/asl/memory/layout.hpp new file mode 100644 index 0000000..02ab518 --- /dev/null +++ b/asl/memory/layout.hpp @@ -0,0 +1,6 @@ +#pragma once + +namespace asl { + +} // namespace asl + diff --git a/asl/meta/BUILD.bazel b/asl/meta/BUILD.bazel index f914bf3..e5b44a7 100644 --- a/asl/meta/BUILD.bazel +++ b/asl/meta/BUILD.bazel @@ -1,18 +1,27 @@ cc_library( name = "meta", hdrs = [ + "empty.hpp", + "funcs.hpp", + "quals.hpp", + "refs.hpp", "types.hpp", ], + srcs = [ + "internal/quals.hpp", + "internal/refs.hpp", + "internal/types.hpp", + ], visibility = ["//visibility:public"], ) -cc_test( - name = "types_tests", +[cc_test( + name = "%s_tests" % name, srcs = [ - "types_tests.cpp", + "%s_tests.cpp" % name, ], deps = [ ":meta", ], -) +) for name in ["empty", "quals", "refs", "types", "funcs"]] diff --git a/asl/meta/empty.hpp b/asl/meta/empty.hpp new file mode 100644 index 0000000..9552fbd --- /dev/null +++ b/asl/meta/empty.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "asl/meta/types.hpp" +#include "asl/meta/quals.hpp" + +namespace asl { + +template concept is_void = same, void>; + +} // namespace asl + diff --git a/asl/meta/empty_tests.cpp b/asl/meta/empty_tests.cpp new file mode 100644 index 0000000..c5bf519 --- /dev/null +++ b/asl/meta/empty_tests.cpp @@ -0,0 +1,17 @@ +#include "asl/meta/empty.hpp" + +using namespace asl; + +struct Empty {}; + +static_assert(is_void); +static_assert(is_void); +static_assert(is_void); +static_assert(is_void); +static_assert(!is_void); +static_assert(!is_void); +static_assert(!is_void); +static_assert(!is_void); + + +int main() { return 0; } diff --git a/asl/meta/funcs.hpp b/asl/meta/funcs.hpp new file mode 100644 index 0000000..f699dac --- /dev/null +++ b/asl/meta/funcs.hpp @@ -0,0 +1,11 @@ +#pragma once + +#include "asl/meta/internal/quals.hpp" +#include "asl/meta/refs.hpp" + +namespace asl { + +template concept is_func = internal::is_const::remove> && !is_any_ref; + +} // namespace asl + diff --git a/asl/meta/funcs_tests.cpp b/asl/meta/funcs_tests.cpp new file mode 100644 index 0000000..f2f40a2 --- /dev/null +++ b/asl/meta/funcs_tests.cpp @@ -0,0 +1,14 @@ +#include "asl/meta/funcs.hpp" + +using namespace asl; + +static_assert(!is_func); +static_assert(!is_func); +static_assert(!is_func); +static_assert(!is_func); +static_assert(is_func); +static_assert(is_func); +static_assert(is_func); +static_assert(!is_func); + +int main() { return 0; } diff --git a/asl/meta/internal/quals.hpp b/asl/meta/internal/quals.hpp new file mode 100644 index 0000000..869cc89 --- /dev/null +++ b/asl/meta/internal/quals.hpp @@ -0,0 +1,16 @@ +#pragma once + +#include "asl/meta/types.hpp" + +namespace asl::internal { + +template struct const_helper { using add = const T; using remove = T; }; +template struct const_helper { using add = const T; using remove = T; }; + +template concept is_const = same::add>; + +template struct volatile_helper { using add = volatile T; using remove = T; }; +template struct volatile_helper { using add = volatile T; using remove = T; }; + +} // namespace asl::internal + diff --git a/asl/meta/internal/refs.hpp b/asl/meta/internal/refs.hpp new file mode 100644 index 0000000..b21a0a1 --- /dev/null +++ b/asl/meta/internal/refs.hpp @@ -0,0 +1,45 @@ +#pragma once + +#include "asl/meta/types.hpp" + +namespace asl::internal { + +template +inline constexpr bool is_referenceable = false; + +template +inline constexpr bool is_referenceable> = true; + +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; }; + +template +struct is_ref_helper +{ + static inline constexpr bool lref = false; + static inline constexpr bool rref = false; +}; + +template +struct is_ref_helper +{ + static inline constexpr bool lref = true; + static inline constexpr bool rref = false; +}; + +template +struct is_ref_helper +{ + static inline constexpr bool lref = false; + static inline constexpr bool rref = true; +}; + +} // namespace asl::internal + diff --git a/asl/meta/internal/types.hpp b/asl/meta/internal/types.hpp new file mode 100644 index 0000000..f635de5 --- /dev/null +++ b/asl/meta/internal/types.hpp @@ -0,0 +1,9 @@ +#pragma once + +namespace asl::internal { + +template inline constexpr bool is_same = false; +template inline constexpr bool is_same = true; + +} // namespace asl::internal + diff --git a/asl/meta/quals.hpp b/asl/meta/quals.hpp new file mode 100644 index 0000000..9671043 --- /dev/null +++ b/asl/meta/quals.hpp @@ -0,0 +1,22 @@ +#pragma once + +#include "asl/meta/types.hpp" +#include "asl/meta/funcs.hpp" +#include "asl/meta/refs.hpp" +#include "asl/meta/internal/quals.hpp" + +namespace asl { + +template concept is_const = internal::is_const; +template concept is_volatile = !is_any_ref && !is_func && same::add>; + +template using as_const_t = internal::const_helper::add; +template using un_const_t = internal::const_helper::remove; + +template using as_volatile_t = internal::volatile_helper::add; +template using un_volatile_t = internal::volatile_helper::remove; + +template using un_qual_t = un_volatile_t>; + +} // namespace asl + diff --git a/asl/meta/quals_tests.cpp b/asl/meta/quals_tests.cpp new file mode 100644 index 0000000..37ecc6c --- /dev/null +++ b/asl/meta/quals_tests.cpp @@ -0,0 +1,51 @@ +#include "asl/meta/quals.hpp" +#include "asl/meta/types.hpp" + +using namespace asl; + +static_assert(!is_const); +static_assert(is_const); +static_assert(!is_const); +static_assert(is_const); + +static_assert(!is_volatile); +static_assert(!is_volatile); +static_assert(is_volatile); +static_assert(is_volatile); + +static_assert(!is_const); +static_assert(is_const); + +static_assert(is_const); +static_assert(is_const); + +static_assert(is_const); +static_assert(is_const); +static_assert(is_const); + +static_assert(!is_volatile); +static_assert(!is_volatile); + +static_assert(same, const int>); +static_assert(same, const int>); +static_assert(same, int>); +static_assert(same, int>); + +static_assert(same, const int[]>); +static_assert(same, const int[5]>); + +static_assert(same, volatile int>); +static_assert(same, volatile int>); +static_assert(same, int>); +static_assert(same, int>); + +static_assert(same, volatile int[]>); +static_assert(same, volatile int[5]>); + +static_assert(same, int>); +static_assert(same, int>); +static_assert(same, int>); +static_assert(same, int>); +static_assert(same, int>); + +int main() { return 0; } diff --git a/asl/meta/refs.hpp b/asl/meta/refs.hpp new file mode 100644 index 0000000..b72458a --- /dev/null +++ b/asl/meta/refs.hpp @@ -0,0 +1,21 @@ +#pragma once + +#include "asl/meta/internal/refs.hpp" + +namespace asl { + +template concept referenceable = internal::is_referenceable; + +template concept is_ref = internal::is_ref_helper::lref; +template concept is_rref = internal::is_ref_helper::rref; +template concept is_any_ref = is_ref || is_rref; + +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/refs_tests.cpp b/asl/meta/refs_tests.cpp new file mode 100644 index 0000000..49d4f23 --- /dev/null +++ b/asl/meta/refs_tests.cpp @@ -0,0 +1,33 @@ +#include "asl/meta/refs.hpp" +#include "asl/meta/types.hpp" + +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_ref); +static_assert(!is_rref); +static_assert(!is_any_ref); + +static_assert(is_ref); +static_assert(!is_rref); +static_assert(is_any_ref); + +static_assert(!is_ref); +static_assert(is_rref); +static_assert(is_any_ref); + +static_assert(!is_any_ref); +static_assert(!is_any_ref); +static_assert(!is_any_ref); + +int main() { return 0; } diff --git a/asl/meta/types.hpp b/asl/meta/types.hpp index 79ccf5e..bfc2998 100644 --- a/asl/meta/types.hpp +++ b/asl/meta/types.hpp @@ -1,36 +1,13 @@ #pragma once -namespace asl { +#include "asl/meta/internal/types.hpp" +namespace asl { + template using void_t = void; -template -inline constexpr bool is_referenceable = false; - -template -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_)) +template +concept same = internal::is_same && internal::is_same; } // namespace asl diff --git a/asl/meta/types_tests.cpp b/asl/meta/types_tests.cpp index 2e3de25..180ecda 100644 --- a/asl/meta/types_tests.cpp +++ b/asl/meta/types_tests.cpp @@ -2,15 +2,9 @@ using namespace asl; -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); +static_assert(same); +static_assert(same); +static_assert(!same); +static_assert(!same); int main() { return 0; } -- cgit