summaryrefslogtreecommitdiff
path: root/asl
diff options
context:
space:
mode:
authorSteven Le Rouzic <steven.lerouzic@gmail.com>2024-08-01 00:56:05 +0200
committerSteven Le Rouzic <steven.lerouzic@gmail.com>2024-08-01 00:56:05 +0200
commit4228e82740f62b841799cfca04861fa217fb93a5 (patch)
tree30bd93b9c62e87d8b1416344d21ba84cfb66ae2a /asl
parent4698812fdc2d9eeea03f26307d6e7e626aaec12b (diff)
More work on taxonomy
Diffstat (limited to 'asl')
-rw-r--r--asl/memory/BUILD.bazel10
-rw-r--r--asl/memory/layout.hpp6
-rw-r--r--asl/meta/BUILD.bazel17
-rw-r--r--asl/meta/empty.hpp11
-rw-r--r--asl/meta/empty_tests.cpp17
-rw-r--r--asl/meta/funcs.hpp11
-rw-r--r--asl/meta/funcs_tests.cpp14
-rw-r--r--asl/meta/internal/quals.hpp16
-rw-r--r--asl/meta/internal/refs.hpp45
-rw-r--r--asl/meta/internal/types.hpp9
-rw-r--r--asl/meta/quals.hpp22
-rw-r--r--asl/meta/quals_tests.cpp51
-rw-r--r--asl/meta/refs.hpp21
-rw-r--r--asl/meta/refs_tests.cpp33
-rw-r--r--asl/meta/types.hpp33
-rw-r--r--asl/meta/types_tests.cpp14
16 files changed, 288 insertions, 42 deletions
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<typename T> concept is_void = same<un_qual_t<T>, 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<void>);
+static_assert(is_void<const void>);
+static_assert(is_void<volatile void>);
+static_assert(is_void<const void>);
+static_assert(!is_void<Empty>);
+static_assert(!is_void<int>);
+static_assert(!is_void<int&>);
+static_assert(!is_void<int()>);
+
+
+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<typename T> concept is_func = internal::is_const<typename internal::const_helper<T>::remove> && !is_any_ref<T>;
+
+} // 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<int>);
+static_assert(!is_func<int&>);
+static_assert(!is_func<const int>);
+static_assert(!is_func<void>);
+static_assert(is_func<void()>);
+static_assert(is_func<void() const>);
+static_assert(is_func<void() &&>);
+static_assert(!is_func<void(*)()>);
+
+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<typename T> struct const_helper { using add = const T; using remove = T; };
+template<typename T> struct const_helper<const T> { using add = const T; using remove = T; };
+
+template<typename T> concept is_const = same<T, typename internal::const_helper<T>::add>;
+
+template<typename T> struct volatile_helper { using add = volatile T; using remove = T; };
+template<typename T> struct volatile_helper<volatile T> { 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<typename T, typename = void>
+inline constexpr bool is_referenceable = false;
+
+template<typename T>
+inline constexpr bool is_referenceable<T, void_t<T&>> = true;
+
+template<typename T, bool = is_referenceable<T>>
+struct as_ref_helper { using lvalue = T; using rvalue = T; };
+
+template<typename T>
+struct as_ref_helper<T, true> { using lvalue = T&; using rvalue = T&&; };
+
+template<typename T> struct un_ref_helper { using type = T; };
+template<typename T> struct un_ref_helper<T&> { using type = T; };
+template<typename T> struct un_ref_helper<T&&> { using type = T; };
+
+template<typename T>
+struct is_ref_helper
+{
+ static inline constexpr bool lref = false;
+ static inline constexpr bool rref = false;
+};
+
+template<typename T>
+struct is_ref_helper<T&>
+{
+ static inline constexpr bool lref = true;
+ static inline constexpr bool rref = false;
+};
+
+template<typename T>
+struct is_ref_helper<T&&>
+{
+ 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<typename U, typename V> inline constexpr bool is_same = false;
+template<typename T> inline constexpr bool is_same<T, T> = 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<typename T> concept is_const = internal::is_const<T>;
+template<typename T> concept is_volatile = !is_any_ref<T> && !is_func<T> && same<T, typename internal::volatile_helper<T>::add>;
+
+template<typename T> using as_const_t = internal::const_helper<T>::add;
+template<typename T> using un_const_t = internal::const_helper<T>::remove;
+
+template<typename T> using as_volatile_t = internal::volatile_helper<T>::add;
+template<typename T> using un_volatile_t = internal::volatile_helper<T>::remove;
+
+template<typename T> using un_qual_t = un_volatile_t<un_const_t<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<int>);
+static_assert(is_const<const int>);
+static_assert(!is_const<volatile int>);
+static_assert(is_const<const volatile int>);
+
+static_assert(!is_volatile<int>);
+static_assert(!is_volatile<const int>);
+static_assert(is_volatile<volatile int>);
+static_assert(is_volatile<const volatile int>);
+
+static_assert(!is_const<const int*>);
+static_assert(is_const<const int* const>);
+
+static_assert(is_const<const int&>);
+static_assert(is_const<int&>);
+
+static_assert(is_const<void()>);
+static_assert(is_const<void() const>);
+static_assert(is_const<void() const &>);
+
+static_assert(!is_volatile<int&>);
+static_assert(!is_volatile<void()>);
+
+static_assert(same<as_const_t<int>, const int>);
+static_assert(same<as_const_t<const int>, const int>);
+static_assert(same<un_const_t<int>, int>);
+static_assert(same<un_const_t<const int>, int>);
+
+static_assert(same<as_const_t<int[]>, const int[]>);
+static_assert(same<as_const_t<int[5]>, const int[5]>);
+
+static_assert(same<as_volatile_t<int>, volatile int>);
+static_assert(same<as_volatile_t<volatile int>, volatile int>);
+static_assert(same<un_volatile_t<int>, int>);
+static_assert(same<un_volatile_t<volatile int>, int>);
+
+static_assert(same<as_volatile_t<int[]>, volatile int[]>);
+static_assert(same<as_volatile_t<int[5]>, volatile int[5]>);
+
+static_assert(same<un_qual_t<int>, int>);
+static_assert(same<un_qual_t<const int>, int>);
+static_assert(same<un_qual_t<volatile int>, int>);
+static_assert(same<un_qual_t<const volatile int>, int>);
+static_assert(same<un_qual_t<volatile const int>, 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<typename T> concept referenceable = internal::is_referenceable<T>;
+
+template<typename T> concept is_ref = internal::is_ref_helper<T>::lref;
+template<typename T> concept is_rref = internal::is_ref_helper<T>::rref;
+template<typename T> concept is_any_ref = is_ref<T> || is_rref<T>;
+
+template<typename T> using as_ref_t = internal::as_ref_helper<T>::lvalue;
+template<typename T> using as_rref_t = internal::as_ref_helper<T>::rvalue;
+
+template<typename T> using un_ref_t = internal::un_ref_helper<T>::type;
+
+#define AslMove(expr_) (static_cast<::asl::as_rref_t<::asl::un_ref_t<decltype(expr_)>>>(expr_))
+#define AslForward(expr_) (static_cast<::asl::as_rref_t<decltype(expr_)>>(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<int>);
+static_assert(referenceable<int&>);
+static_assert(referenceable<int&&>);
+static_assert(!referenceable<void>);
+static_assert(referenceable<void*>);
+static_assert(referenceable<void()>);
+static_assert(referenceable<void(*)()>);
+static_assert(!referenceable<void() const>);
+static_assert(!referenceable<void() &>);
+static_assert(!referenceable<void() const &&>);
+
+static_assert(!is_ref<int>);
+static_assert(!is_rref<int>);
+static_assert(!is_any_ref<int>);
+
+static_assert(is_ref<int&>);
+static_assert(!is_rref<int&>);
+static_assert(is_any_ref<int&>);
+
+static_assert(!is_ref<int&&>);
+static_assert(is_rref<int&&>);
+static_assert(is_any_ref<int&&>);
+
+static_assert(!is_any_ref<void()>);
+static_assert(!is_any_ref<void() const>);
+static_assert(!is_any_ref<void() &>);
+
+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<typename T> using void_t = void;
-template<typename T, typename = void>
-inline constexpr bool is_referenceable = false;
-
-template<typename T>
-inline constexpr bool is_referenceable<T, void_t<T&>> = true;
-
-namespace internal {
-
-template<typename T, bool = is_referenceable<T>>
-struct as_ref_helper { using lvalue = T; using rvalue = T; };
-
-template<typename T>
-struct as_ref_helper<T, true> { using lvalue = T&; using rvalue = T&&; };
-
-template<typename T> struct un_ref_helper { using type = T; };
-template<typename T> struct un_ref_helper<T&> { using type = T; };
-template<typename T> struct un_ref_helper<T&&> { using type = T; };
-
-} // namespace internal
-
-template<typename T> using as_ref_t = internal::as_ref_helper<T>::lvalue;
-template<typename T> using as_rref_t = internal::as_ref_helper<T>::rvalue;
-
-template<typename T> using un_ref_t = internal::un_ref_helper<T>::type;
-
-#define AslMove(expr_) (static_cast<::asl::as_rref_t<::asl::un_ref_t<decltype(expr_)>>>(expr_))
-#define AslForward(expr_) (static_cast<::asl::as_rref_t<decltype(expr_)>>(expr_))
+template<typename U, typename V>
+concept same = internal::is_same<U, V> && internal::is_same<V, U>;
} // 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<int>);
-static_assert(is_referenceable<int&>);
-static_assert(is_referenceable<int&&>);
-static_assert(!is_referenceable<void>);
-static_assert(is_referenceable<void*>);
-static_assert(is_referenceable<void()>);
-static_assert(is_referenceable<void(*)()>);
-static_assert(!is_referenceable<void() const>);
-static_assert(!is_referenceable<void() &>);
-static_assert(!is_referenceable<void() const &&>);
+static_assert(same<int, int>);
+static_assert(same<void, void>);
+static_assert(!same<const float, float>);
+static_assert(!same<int, float>);
int main() { return 0; }