From 19ce24de5e8ef31be2925074e962ae23aaf65be0 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Fri, 23 Aug 2024 20:05:22 +0200 Subject: Some work on ptr --- asl/BUILD.bazel | 3 ++- asl/meta.hpp | 19 ++++++++++++++ asl/meta_tests.cpp | 8 ++++++ asl/ptr.hpp | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ asl/ptr_tests.cpp | 14 +++++++++++ 5 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 asl/ptr.hpp create mode 100644 asl/ptr_tests.cpp (limited to 'asl') diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel index c5f443e..4fdeb38 100644 --- a/asl/BUILD.bazel +++ b/asl/BUILD.bazel @@ -3,6 +3,7 @@ cc_library( hdrs = [ "integers.hpp", "meta.hpp", + "ptr.hpp", "utility.hpp", ], visibility = ["//visibility:public"], @@ -17,4 +18,4 @@ cc_library( deps = [ ":asl", ], -) for name in ["integers", "meta"]] +) for name in ["integers", "meta", "ptr"]] diff --git a/asl/meta.hpp b/asl/meta.hpp index b3e0697..411d890 100644 --- a/asl/meta.hpp +++ b/asl/meta.hpp @@ -2,6 +2,10 @@ namespace asl { +template struct types {}; + +struct empty {}; + template struct id { using type = T; }; template struct integral_constant { static constexpr T value = kValue; }; @@ -29,6 +33,12 @@ template auto _as_rref_helper(...) -> id; template using as_lref_t = decltype(_as_lref_helper(0))::type; template using as_rref_t = decltype(_as_rref_helper(0))::type; +template struct _un_ref_t { using type = T; }; +template struct _un_ref_t { using type = T; }; +template struct _un_ref_t { using type = T; }; + +template using un_ref_t = _un_ref_t::type; + template concept constructible = __is_constructible(T, Args...); template concept default_constructible = constructible; @@ -123,4 +133,13 @@ template struct _is_array_helper : true_type {}; template concept is_array = _is_array_helper::value; +template +auto _devoid_helper() +{ + if constexpr (is_void) return id{}; + else return id{}; +} + +template using devoid_t = decltype(_devoid_helper())::type; + } // namespace asl diff --git a/asl/meta_tests.cpp b/asl/meta_tests.cpp index c2b27f4..8293319 100644 --- a/asl/meta_tests.cpp +++ b/asl/meta_tests.cpp @@ -145,4 +145,12 @@ static_assert(!asl::is_array); static_assert(!asl::is_array); static_assert(!asl::is_array); +static_assert(asl::is_same>); +static_assert(asl::is_same>); + +static_assert(asl::is_same>); +static_assert(asl::is_same>); +static_assert(asl::is_same>); +static_assert(asl::is_same>); + int main() { return 0; } diff --git a/asl/ptr.hpp b/asl/ptr.hpp new file mode 100644 index 0000000..2d90e7b --- /dev/null +++ b/asl/ptr.hpp @@ -0,0 +1,74 @@ +#pragma once + +#include "asl/integers.hpp" +#include "asl/meta.hpp" + +namespace asl +{ +namespace ptr_internal +{ + +template +struct void_metadata +{ + using metadata = empty; + using pointee = T; +}; + +template +struct array_metadata {}; + +template +struct array_metadata +{ + using metadata = isize_t; + using pointee = T; +}; + +template +struct array_metadata +{ + using metadata = empty; + using pointee = T[N]; +}; + +template +struct object_metadata +{ + using metadata = empty; + using pointee = T; +}; + +template +struct func_metadata +{ + using metadata = empty; + using pointee = tame_t*; +}; + +template +struct ref_metadata +{ + using metadata = empty; + using pointee = un_ref_t*; +}; + +template void_metadata select_ptr_metadata(types); +template array_metadata select_ptr_metadata(types); +template object_metadata select_ptr_metadata(types) requires (!is_array); +template func_metadata select_ptr_metadata(types); +template ref_metadata select_ptr_metadata(types); + +template +using metadata = decltype(select_ptr_metadata(types{})); + +} // namespace ptr_internal + +template +concept ptr_metadata = requires +{ + is_object; + is_object; +}; + +} // namespace asl diff --git a/asl/ptr_tests.cpp b/asl/ptr_tests.cpp new file mode 100644 index 0000000..be27f0d --- /dev/null +++ b/asl/ptr_tests.cpp @@ -0,0 +1,14 @@ +#include "asl/ptr.hpp" + +using namespace asl; + +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); +static_assert(ptr_metadata>); + +int main() { return 0; } -- cgit