diff options
author | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-03-29 00:18:28 +0100 |
---|---|---|
committer | Steven Le Rouzic <steven.lerouzic@gmail.com> | 2024-03-29 00:18:57 +0100 |
commit | 3c0d80179c0f2053fb2b892ee9af47200cb5d539 (patch) | |
tree | 8b0598e344e6d97c1c1492af8e25ac36bccdb3f7 | |
parent | b70ed765ff6cf51aff20714e3ec4415b06898059 (diff) |
Separate the std-lite stuff
-rw-r--r-- | deimos/core/BUILD | 1 | ||||
-rw-r--r-- | deimos/core/base.h | 38 | ||||
-rw-r--r-- | deimos/core/hash.h | 8 | ||||
-rw-r--r-- | deimos/core/std.h | 49 |
4 files changed, 55 insertions, 41 deletions
diff --git a/deimos/core/BUILD b/deimos/core/BUILD index 2f0dc2d..134b236 100644 --- a/deimos/core/BUILD +++ b/deimos/core/BUILD @@ -7,6 +7,7 @@ cc_library( "hash.h",
"id_name.h",
"os.h",
+ "std.h",
],
srcs = [
"allocator.cpp",
diff --git a/deimos/core/base.h b/deimos/core/base.h index 0cc48b1..5ff9090 100644 --- a/deimos/core/base.h +++ b/deimos/core/base.h @@ -73,13 +73,6 @@ struct SourceLocation {}
};
-template<typename T> struct RemoveReferenceT { using Type = T; };
-template<typename T> struct RemoveReferenceT<T&> { using Type = T; };
-template<typename T> struct RemoveReferenceT<T&&> { using Type = T; };
-template<typename T> using RemoveReference = RemoveReferenceT<T>::Type;
-
-template<typename T> constexpr bool kIsTriviallyDestructible = __is_trivially_destructible(T);
-
} // namespace deimos
constexpr void* operator new(deimos::uint64, void* ptr)
@@ -87,34 +80,5 @@ constexpr void* operator new(deimos::uint64, void* ptr) return ptr;
}
-namespace std
-{
-
-template<typename T>
-constexpr deimos::RemoveReference<T>&& move(T&& t) noexcept
-{
- return static_cast<deimos::RemoveReference<T>&&>(t);
-}
-
-template<typename T>
-constexpr T&& forward(deimos::RemoveReference<T>& t) noexcept
-{
- return static_cast<T&&>(t);
-}
-
-template<typename T>
-constexpr T&& forward(deimos::RemoveReference<T>&& t) noexcept // NOLINT
-{
- return static_cast<T&&>(t);
-}
-
-template<typename T, typename U = T>
-constexpr T exchange(T& obj, U&& new_value)
-{
- T old_value = std::move(obj);
- obj = std::forward<U>(new_value);
- return old_value;
-}
-
-} // namespace std
+#include "deimos/core/std.h"
diff --git a/deimos/core/hash.h b/deimos/core/hash.h index 6ad30b0..e6e9cc8 100644 --- a/deimos/core/hash.h +++ b/deimos/core/hash.h @@ -5,7 +5,7 @@ namespace deimos
{
-constexpr uint64 MurmurHash3_GetBlock64(const byte* key, uint64 block)
+constexpr uint64 MurmurHash3_GetBlock64(const char* key, uint64 block)
{
// NOLINTBEGIN
key += block * 8;
@@ -41,7 +41,7 @@ constexpr uint64 MurmurHash3_Fmix64(uint64 k) return k;
}
-constexpr uint128 MurmurHash3_x64_128(const byte* key, uint64 len)
+constexpr uint128 MurmurHash3_x64_128(const char* key, uint64 len)
{
if consteval { return { 12, 12 }; }
@@ -72,7 +72,7 @@ constexpr uint128 MurmurHash3_x64_128(const byte* key, uint64 len) //----------
// tail
- const byte* tail = key + nblocks * 16;
+ const char* tail = key + nblocks * 16;
uint64 k1 = 0;
uint64 k2 = 0;
@@ -119,7 +119,7 @@ constexpr uint128 MurmurHash3_x64_128(const byte* key, uint64 len) constexpr uint128 MurmurHash3_x64_128(gsl::czstring str)
{
- return MurmurHash3_x64_128(BitCast<const byte*>(str), __builtin_strlen(str));
+ return MurmurHash3_x64_128(str, __builtin_strlen(str));
}
} // namespace deimos
diff --git a/deimos/core/std.h b/deimos/core/std.h new file mode 100644 index 0000000..1c611cd --- /dev/null +++ b/deimos/core/std.h @@ -0,0 +1,49 @@ +#pragma once
+
+namespace std
+{
+
+template<typename U, typename V> constexpr bool _is_same_helper = false;
+template<typename T> constexpr bool _is_same_helper<T, T> = true;
+template<typename U, typename V> concept same_as = _is_same_helper<U, V> && _is_same_helper<V, U>;
+
+template<typename T> struct remove_reference { using type = T; };
+template<typename T> struct remove_reference<T&> { using type = T; };
+template<typename T> struct remove_reference<T&&> { using type = T; };
+template<typename T> using remove_reference_t = remove_reference<T>::type;
+
+template<typename T>
+constexpr remove_reference_t<T>&& move(T&& r) noexcept
+{
+ return static_cast<remove_reference_t<T>&&>(r);
+}
+
+template<typename T>
+constexpr T&& forward(remove_reference_t<T>& r) noexcept
+{
+ return static_cast<T&&>(r);
+}
+
+template<typename T>
+constexpr T&& forward(remove_reference_t<T>&& r) noexcept // NOLINT
+{
+ return static_cast<T&&>(r);
+}
+
+template<typename T, typename U>
+constexpr T exchange(T& obj, U&& new_value)
+{
+ T old_value = std::move(obj);
+ obj = std::forward<U>(new_value);
+ return old_value;
+}
+
+} // namespace std
+
+static_assert(std::same_as<int, int>, "");
+static_assert(!std::same_as<int, void>, "");
+
+static_assert(std::same_as<std::remove_reference_t<int>, int>, "");
+static_assert(std::same_as<std::remove_reference_t<int&>, int>, "");
+static_assert(std::same_as<std::remove_reference_t<int&&>, int>, "");
+
|