From aa427cb5fe7564a85703f14f76f854419274decc Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Wed, 4 Sep 2024 00:11:04 +0200 Subject: Bleh --- asl/BUILD.bazel | 5 +- asl/annotations.hpp | 12 +++++ asl/meta.hpp | 9 ---- asl/meta_tests.cpp | 6 --- asl/option.hpp | 13 ++++++ asl/option_tests.cpp | 3 ++ asl/ptr.hpp | 127 -------------------------------------------------- asl/ptr_tests.cpp | 16 ------- asl/utility.hpp | 24 ++++++---- asl/utility_tests.cpp | 3 ++ 10 files changed, 50 insertions(+), 168 deletions(-) create mode 100644 asl/annotations.hpp create mode 100644 asl/option.hpp create mode 100644 asl/option_tests.cpp delete mode 100644 asl/ptr.hpp delete mode 100644 asl/ptr_tests.cpp create mode 100644 asl/utility_tests.cpp (limited to 'asl') diff --git a/asl/BUILD.bazel b/asl/BUILD.bazel index 4fdeb38..e5d5eb3 100644 --- a/asl/BUILD.bazel +++ b/asl/BUILD.bazel @@ -1,9 +1,10 @@ cc_library( name = "asl", hdrs = [ + "annotations.hpp", "integers.hpp", "meta.hpp", - "ptr.hpp", + "option.hpp", "utility.hpp", ], visibility = ["//visibility:public"], @@ -18,4 +19,4 @@ cc_library( deps = [ ":asl", ], -) for name in ["integers", "meta", "ptr"]] +) for name in ["integers", "meta", "option", "utility"]] diff --git a/asl/annotations.hpp b/asl/annotations.hpp new file mode 100644 index 0000000..a94834d --- /dev/null +++ b/asl/annotations.hpp @@ -0,0 +1,12 @@ +#pragma once + +#ifndef __clang__ + #error Not a valid environment +#endif + +#ifdef _MSC_VER + #define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] +#else + #define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]] +#endif + diff --git a/asl/meta.hpp b/asl/meta.hpp index 6c650ac..931310f 100644 --- a/asl/meta.hpp +++ b/asl/meta.hpp @@ -136,13 +136,4 @@ 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 a4f3ad8..be0c3d8 100644 --- a/asl/meta_tests.cpp +++ b/asl/meta_tests.cpp @@ -153,15 +153,9 @@ 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>); -using F = void(int) const &; -using Fr = asl::tame_t&; - int main() { return 0; } diff --git a/asl/option.hpp b/asl/option.hpp new file mode 100644 index 0000000..e71eb57 --- /dev/null +++ b/asl/option.hpp @@ -0,0 +1,13 @@ +#pragma once + +#include "asl/meta.hpp" + +namespace asl +{ + +template +class option +{ +}; + +} // namespace asl diff --git a/asl/option_tests.cpp b/asl/option_tests.cpp new file mode 100644 index 0000000..41c67e1 --- /dev/null +++ b/asl/option_tests.cpp @@ -0,0 +1,3 @@ +#include "asl/option.hpp" + +int main() { return 0; } diff --git a/asl/ptr.hpp b/asl/ptr.hpp deleted file mode 100644 index 1da632a..0000000 --- a/asl/ptr.hpp +++ /dev/null @@ -1,127 +0,0 @@ -#pragma once - -#include "asl/integers.hpp" -#include "asl/meta.hpp" -#include "asl/utility.hpp" - -namespace asl -{ - -// @Todo Shitty span, improve this -template -struct span -{ - static constexpr bool kIsDynamic = kLen < 0; - - using size_type = select_t; - - constexpr span(T* begin, isize_t len) requires kIsDynamic - : m_begin{begin} - , m_len{len} - {} - - constexpr span(T* begin) requires (!kIsDynamic) - : m_begin{begin} - , m_len{} - {} - - T* m_begin; - ASL_NO_UNIQUE_ADDRESS size_type m_len; -}; - -namespace ptr_internal -{ - -template -struct void_metadata -{ - using metadata = empty; - using pointee = T; - - constexpr auto deref(pointee* ptr) { return ptr; } -}; - -template -struct array_metadata {}; - -template -struct array_metadata -{ - using metadata = isize_t; - using pointee = T; - - constexpr auto deref(pointee* ptr) - { - return span(ptr, m_len); - } - - isize_t m_len; -}; - -template -struct array_metadata -{ - using metadata = empty; - using pointee = T[N]; - - constexpr auto deref(pointee* ptr) - { - return span(static_cast(*ptr)); - } -}; - -template -struct object_metadata -{ - using metadata = empty; - using pointee = T; - - constexpr auto deref(pointee* ptr) { return ptr; } -}; - -template -struct ptr_like_metadata -{ - using metadata = empty; - using pointee = un_ref_t>* const; - - constexpr auto deref(pointee* ptr) { return *ptr; } -}; - -template -constexpr auto select_ptr_metadata() -{ - if constexpr (is_void) return id>{}; - else if constexpr (is_array) return id>{}; - else if constexpr (is_object) return id>{}; - else return id>{}; -} - -template -using metadata = decltype(select_ptr_metadata())::type; - -} // namespace ptr_internal - -template -concept ptr_metadata = requires (T metadata, typename T::pointee* ptr) -{ - is_object; - is_object; - - { metadata.deref(ptr) }; -}; - -template -class ptr -{ - using meta = ptr_internal::metadata; - static_assert(ptr_metadata); - - meta::pointee* m_ptr; - ASL_NO_UNIQUE_ADDRESS meta m_meta; - -public: - -}; - -} // namespace asl diff --git a/asl/ptr_tests.cpp b/asl/ptr_tests.cpp deleted file mode 100644 index 64c0ae2..0000000 --- a/asl/ptr_tests.cpp +++ /dev/null @@ -1,16 +0,0 @@ -#include "asl/ptr.hpp" - -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); -static_assert(asl::ptr_metadata>); - -static_assert(sizeof(asl::ptr) == sizeof(int*)); -static_assert(sizeof(asl::ptr) == sizeof(int*) * 2); -static_assert(sizeof(asl::ptr) == sizeof(int*)); - -int main() { return 0; } diff --git a/asl/utility.hpp b/asl/utility.hpp index a94834d..6cbff8e 100644 --- a/asl/utility.hpp +++ b/asl/utility.hpp @@ -1,12 +1,20 @@ #pragma once -#ifndef __clang__ - #error Not a valid environment -#endif +#include "asl/meta.hpp" -#ifdef _MSC_VER - #define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]] -#else - #define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]] -#endif +#define ASL_MOVE(expr_) (static_cast<::asl::un_ref_t&&>(expr_)) +#define ASL_FWD(expr_) (static_cast(expr_)) + +namespace asl +{ + +template +T exchange(T& obj, U&& new_value) +{ + T old_value = ASL_MOVE(obj); + obj = ASL_FORWARD(new_value); + return old_value; +} + +} // namespace asl diff --git a/asl/utility_tests.cpp b/asl/utility_tests.cpp new file mode 100644 index 0000000..5802cec --- /dev/null +++ b/asl/utility_tests.cpp @@ -0,0 +1,3 @@ +#include "asl/utility.hpp" + +int main() { return 0; } -- cgit