summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2022-10-21 19:12:36 +0200
committerStanislaw Halik <sthalik@misaki.pl>2022-10-21 19:12:36 +0200
commit376dccfc3d4f1ae6d2a4b8d5a93e55bcd5482f52 (patch)
tree148da4965ab1bb26dfe34ac44d79e7b2571bdab3 /compat
parent387ab8e946398c29bd462041689e9da4152ec52b (diff)
literal size type nonsense
Diffstat (limited to 'compat')
-rw-r--r--compat/literal-size-type.hpp15
1 files changed, 11 insertions, 4 deletions
diff --git a/compat/literal-size-type.hpp b/compat/literal-size-type.hpp
index 1eef90d3..a9034031 100644
--- a/compat/literal-size-type.hpp
+++ b/compat/literal-size-type.hpp
@@ -1,20 +1,26 @@
#pragma once
+#if !(defined __cpp_size_t_suffix && __cpp_size_t_suffix >= 202006L)
#include <cstddef>
+#include <type_traits>
+#include <cstdlib>
+#include <limits>
namespace floormat {
#ifdef __clang__
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wuser-defined-literals"
+#pragma clang diagnostic ignored "-Wtautological-type-limit-compare"
#elif defined _MSC_VER
#pragma warning(push)
#pragma warning(disable : 4455)
#endif
-constexpr std::size_t operator"" z(unsigned long long int x) noexcept
-{
- return std::size_t(x);
-}
+[[maybe_unused]] constexpr std::size_t operator"" zu(unsigned long long int x) noexcept { if constexpr (sizeof(decltype(x)) > sizeof(std::size_t)) if (x > std::numeric_limits<std::size_t>::max()) std::abort(); return std::size_t(x); }
+[[maybe_unused]] constexpr std::size_t operator"" ZU(unsigned long long int x) noexcept { if constexpr (sizeof(decltype(x)) > sizeof(std::size_t)) if (x > std::numeric_limits<std::size_t>::max()) std::abort(); return std::size_t(x); }
+
+[[maybe_unused]] constexpr auto operator"" z(unsigned long long int x) noexcept { if constexpr (sizeof(decltype(x)) >= sizeof(std::size_t)) if (x > (std::size_t)std::numeric_limits<std::make_signed_t<std::size_t>>::max()) std::abort(); return std::make_signed_t<std::size_t>(x); }
+[[maybe_unused]] constexpr auto operator"" Z(unsigned long long int x) noexcept { if constexpr (sizeof(decltype(x)) >= sizeof(std::size_t)) if (x > (std::size_t)std::numeric_limits<std::make_signed_t<std::size_t>>::max()) std::abort(); return std::make_signed_t<std::size_t>(x); }
#ifdef __clang__
#pragma clang diagnostic pop
@@ -23,3 +29,4 @@ constexpr std::size_t operator"" z(unsigned long long int x) noexcept
#endif
} // namespace floormat
+#endif