This commit is contained in:
2024-09-04 00:11:04 +02:00
parent f0a94256e2
commit aa427cb5fe
11 changed files with 50 additions and 169 deletions

View File

@ -1,9 +1,10 @@
cc_library( cc_library(
name = "asl", name = "asl",
hdrs = [ hdrs = [
"annotations.hpp",
"integers.hpp", "integers.hpp",
"meta.hpp", "meta.hpp",
"ptr.hpp", "option.hpp",
"utility.hpp", "utility.hpp",
], ],
visibility = ["//visibility:public"], visibility = ["//visibility:public"],
@ -18,4 +19,4 @@ cc_library(
deps = [ deps = [
":asl", ":asl",
], ],
) for name in ["integers", "meta", "ptr"]] ) for name in ["integers", "meta", "option", "utility"]]

12
asl/annotations.hpp Normal file
View File

@ -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

View File

@ -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> 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 } // namespace asl

View File

@ -153,15 +153,9 @@ static_assert(!asl::is_array<void>);
static_assert(!asl::is_array<void(int)>); static_assert(!asl::is_array<void(int)>);
static_assert(!asl::is_array<int(float) const && noexcept>); 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&>>);
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; } int main() { return 0; }

13
asl/option.hpp Normal file
View File

@ -0,0 +1,13 @@
#pragma once
#include "asl/meta.hpp"
namespace asl
{
template<is_object T>
class option
{
};
} // namespace asl

3
asl/option_tests.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "asl/option.hpp"
int main() { return 0; }

View File

@ -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

View File

@ -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; }

View File

@ -1,12 +1,20 @@
#pragma once #pragma once
#ifndef __clang__ #include "asl/meta.hpp"
#error Not a valid environment
#endif
#ifdef _MSC_VER #define ASL_MOVE(expr_) (static_cast<::asl::un_ref_t<decltype(expr_)>&&>(expr_))
#define ASL_NO_UNIQUE_ADDRESS [[msvc::no_unique_address]]
#else
#define ASL_NO_UNIQUE_ADDRESS [[no_unique_address]]
#endif
#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

3
asl/utility_tests.cpp Normal file
View File

@ -0,0 +1,3 @@
#include "asl/utility.hpp"
int main() { return 0; }

View File

@ -1 +0,0 @@
Platform config