From 3c0d80179c0f2053fb2b892ee9af47200cb5d539 Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Fri, 29 Mar 2024 00:18:28 +0100 Subject: Separate the std-lite stuff --- deimos/core/BUILD | 1 + deimos/core/base.h | 38 +------------------------------------- deimos/core/hash.h | 8 ++++---- deimos/core/std.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 55 insertions(+), 41 deletions(-) create mode 100644 deimos/core/std.h (limited to 'deimos/core') 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 struct RemoveReferenceT { using Type = T; }; -template struct RemoveReferenceT { using Type = T; }; -template struct RemoveReferenceT { using Type = T; }; -template using RemoveReference = RemoveReferenceT::Type; - -template 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 -constexpr deimos::RemoveReference&& move(T&& t) noexcept -{ - return static_cast&&>(t); -} - -template -constexpr T&& forward(deimos::RemoveReference& t) noexcept -{ - return static_cast(t); -} - -template -constexpr T&& forward(deimos::RemoveReference&& t) noexcept // NOLINT -{ - return static_cast(t); -} - -template -constexpr T exchange(T& obj, U&& new_value) -{ - T old_value = std::move(obj); - obj = std::forward(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(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 constexpr bool _is_same_helper = false; +template constexpr bool _is_same_helper = true; +template concept same_as = _is_same_helper && _is_same_helper; + +template struct remove_reference { using type = T; }; +template struct remove_reference { using type = T; }; +template struct remove_reference { using type = T; }; +template using remove_reference_t = remove_reference::type; + +template +constexpr remove_reference_t&& move(T&& r) noexcept +{ + return static_cast&&>(r); +} + +template +constexpr T&& forward(remove_reference_t& r) noexcept +{ + return static_cast(r); +} + +template +constexpr T&& forward(remove_reference_t&& r) noexcept // NOLINT +{ + return static_cast(r); +} + +template +constexpr T exchange(T& obj, U&& new_value) +{ + T old_value = std::move(obj); + obj = std::forward(new_value); + return old_value; +} + +} // namespace std + +static_assert(std::same_as, ""); +static_assert(!std::same_as, ""); + +static_assert(std::same_as, int>, ""); +static_assert(std::same_as, int>, ""); +static_assert(std::same_as, int>, ""); + -- cgit