summaryrefslogtreecommitdiffhomepage
path: root/compat
diff options
context:
space:
mode:
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