From 5c3bcde8f859b08275fa09f32800360ee541d5bd Mon Sep 17 00:00:00 2001 From: Stanislaw Halik Date: Mon, 17 Oct 2022 11:35:46 +0200 Subject: a --- compat/assert.hpp | 16 ++++++++++++++++ compat/defs.hpp | 2 ++ compat/int-hash.hpp | 30 ++++++++++++++++++++++++++++++ 3 files changed, 48 insertions(+) create mode 100644 compat/int-hash.hpp (limited to 'compat') diff --git a/compat/assert.hpp b/compat/assert.hpp index 860a9cde..04c5acbe 100644 --- a/compat/assert.hpp +++ b/compat/assert.hpp @@ -59,3 +59,19 @@ constexpr inline void abort(const char (&fmt)[N], Xs... xs) noexcept #define ERR(...) ::floormat::detail::emit_debug("error: ", __VA_ARGS__) #define MESSAGE(...) ::floormat::detail::emit_debug("", __VA_ARGS__) #define DEBUG(...) ::floormat::detail::emit_debug("", __VA_ARGS__) + +namespace floormat { + +template +struct static_warning_ final { + [[deprecated]] constexpr static_warning_() = default; +}; + +template<> +struct static_warning_ final { + constexpr static_warning_() = default; +}; + +#define static_warning(...) do { (void)static_warning_<(__VA_ARGS__)>{}; } while(false) + +} // namespace floormat diff --git a/compat/defs.hpp b/compat/defs.hpp index 818e004b..632bafe5 100644 --- a/compat/defs.hpp +++ b/compat/defs.hpp @@ -15,3 +15,5 @@ #define DECLARE_DELETED_COPY_ASSIGNMENT(type) \ type(const type&) = delete; \ type& operator=(const type&) = delete + + diff --git a/compat/int-hash.hpp b/compat/int-hash.hpp new file mode 100644 index 00000000..43b92605 --- /dev/null +++ b/compat/int-hash.hpp @@ -0,0 +1,30 @@ +#pragma once +#include + +namespace floormat { + +constexpr inline std::size_t int_hash(std::size_t x) noexcept +{ + if constexpr(sizeof(std::size_t) == 4) + { + // by Chris Wellons + x ^= x >> 15; + x *= 0x2c1b3c6dU; + x ^= x >> 12; + x *= 0x297a2d39U; + x ^= x >> 15; + } + else if constexpr(sizeof(std::size_t) == 8) + { + // splitmix64 by George Marsaglia + x ^= x >> 30; + x *= 0xbf58476d1ce4e5b9U; + x ^= x >> 27; + x *= 0x94d049bb133111ebU; + x ^= x >> 31; + } + + return x; +} + +} // namespace floormat -- cgit v1.2.3