diff options
| author | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 11:35:46 +0200 |
|---|---|---|
| committer | Stanislaw Halik <sthalik@misaki.pl> | 2022-10-17 11:35:46 +0200 |
| commit | 5c3bcde8f859b08275fa09f32800360ee541d5bd (patch) | |
| tree | d428f3d1facbb433d787c25d55f20b11ac92aadd /compat | |
| parent | 66f89e04a50ad6ed8448c20c1731a3750d08e624 (diff) | |
a
Diffstat (limited to 'compat')
| -rw-r--r-- | compat/assert.hpp | 16 | ||||
| -rw-r--r-- | compat/defs.hpp | 2 | ||||
| -rw-r--r-- | compat/int-hash.hpp | 30 |
3 files changed, 48 insertions, 0 deletions
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<bool> +struct static_warning_ final { + [[deprecated]] constexpr static_warning_() = default; +}; + +template<> +struct static_warning_<true> 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 <cstddef> + +namespace floormat { + +constexpr inline std::size_t int_hash(std::size_t x) noexcept +{ + if constexpr(sizeof(std::size_t) == 4) + { + // by Chris Wellons <https://nullprogram.com/blog/2018/07/31/> + 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 |
