diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-09-04 00:11:04 +0200 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-09-04 00:11:04 +0200 |
commit | aa427cb5fe7564a85703f14f76f854419274decc (patch) | |
tree | 8395e90d6ce25f8044fb5d2a1a21eecb6e80ed08 /asl | |
parent | f0a94256e25c844ca2ff99377bc8b2fb94f69e84 (diff) |
Bleh
Diffstat (limited to 'asl')
-rw-r--r-- | asl/BUILD.bazel | 5 | ||||
-rw-r--r-- | asl/annotations.hpp | 12 | ||||
-rw-r--r-- | asl/meta.hpp | 9 | ||||
-rw-r--r-- | asl/meta_tests.cpp | 6 | ||||
-rw-r--r-- | asl/option.hpp | 13 | ||||
-rw-r--r-- | asl/option_tests.cpp | 3 | ||||
-rw-r--r-- | asl/ptr.hpp | 127 | ||||
-rw-r--r-- | asl/ptr_tests.cpp | 16 | ||||
-rw-r--r-- | asl/utility.hpp | 24 | ||||
-rw-r--r-- | asl/utility_tests.cpp | 3 |
10 files changed, 50 insertions, 168 deletions
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<typename T, int N> struct _is_array_helper<T[N]> : true_type {}; template<typename T> concept is_array = _is_array_helper<T>::value;
-template<typename T>
-auto _devoid_helper()
-{
- if constexpr (is_void<T>) return id<empty>{};
- else return id<T>{};
-}
-
-template<typename T> using devoid_t = decltype(_devoid_helper<T>())::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<void>); static_assert(!asl::is_array<void(int)>);
static_assert(!asl::is_array<int(float) const && noexcept>);
-static_assert(asl::is_same<int, asl::devoid_t<int>>);
-static_assert(asl::is_same<asl::empty, asl::devoid_t<void>>);
-
static_assert(asl::is_same<int, asl::un_ref_t<int>>);
static_assert(asl::is_same<int, asl::un_ref_t<int&>>);
static_assert(asl::is_same<int, asl::un_ref_t<int&&>>);
static_assert(asl::is_same<int() &, asl::un_ref_t<int() &>>);
-using F = void(int) const &;
-using Fr = asl::tame_t<F>&;
-
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<is_object T>
+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<is_object T, isize_t kLen> -struct span -{ - static constexpr bool kIsDynamic = kLen < 0; - - using size_type = select_t<kIsDynamic, isize_t, empty>; - - 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<is_void T> -struct void_metadata -{ - using metadata = empty; - using pointee = T; - - constexpr auto deref(pointee* ptr) { return ptr; } -}; - -template<is_array T> -struct array_metadata {}; - -template<is_object T> -struct array_metadata<T[]> -{ - using metadata = isize_t; - using pointee = T; - - constexpr auto deref(pointee* ptr) - { - return span<pointee, -1>(ptr, m_len); - } - - isize_t m_len; -}; - -template<is_object T, isize_t N> -struct array_metadata<T[N]> -{ - using metadata = empty; - using pointee = T[N]; - - constexpr auto deref(pointee* ptr) - { - return span<T, N>(static_cast<T*>(*ptr)); - } -}; - -template<is_object T> -struct object_metadata -{ - using metadata = empty; - using pointee = T; - - constexpr auto deref(pointee* ptr) { return ptr; } -}; - -template<typename T> -struct ptr_like_metadata -{ - using metadata = empty; - using pointee = un_ref_t<tame_t<T>>* const; - - constexpr auto deref(pointee* ptr) { return *ptr; } -}; - -template<typename T> -constexpr auto select_ptr_metadata() -{ - if constexpr (is_void<T>) return id<void_metadata<T>>{}; - else if constexpr (is_array<T>) return id<array_metadata<T>>{}; - else if constexpr (is_object<T>) return id<object_metadata<T>>{}; - else return id<ptr_like_metadata<T>>{}; -} - -template<typename T> -using metadata = decltype(select_ptr_metadata<T>())::type; - -} // namespace ptr_internal - -template<typename T> -concept ptr_metadata = requires (T metadata, typename T::pointee* ptr) -{ - is_object<typename T::metadata>; - is_object<typename T::pointee>; - - { metadata.deref(ptr) }; -}; - -template<typename T> -class ptr -{ - using meta = ptr_internal::metadata<T>; - static_assert(ptr_metadata<meta>); - - 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<asl::ptr_internal::metadata<void>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int[]>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int[56]>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int()>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int(int) const &>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<const int&>>); -static_assert(asl::ptr_metadata<asl::ptr_internal::metadata<int&&>>); - -static_assert(sizeof(asl::ptr<int>) == sizeof(int*)); -static_assert(sizeof(asl::ptr<int[]>) == sizeof(int*) * 2); -static_assert(sizeof(asl::ptr<int[67]>) == 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<decltype(expr_)>&&>(expr_))
+#define ASL_FWD(expr_) (static_cast<decltype(expr_)&&>(expr_))
+
+namespace asl
+{
+
+template<typename T, typename U>
+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; }
|