diff --git a/include/stdx/compiler.hpp b/include/stdx/compiler.hpp index 05e723a..a47159d 100644 --- a/include/stdx/compiler.hpp +++ b/include/stdx/compiler.hpp @@ -22,6 +22,14 @@ #endif #endif +#ifndef CONSTEVAL_UDL +#if defined(__clang__) +#define CONSTEVAL_UDL constexpr +#else +#define CONSTEVAL_UDL CONSTEVAL +#endif +#endif + #ifndef USING_ATTR_NS #if defined(__clang__) #define USING_ATTR_NS using clang: diff --git a/include/stdx/ct_format.hpp b/include/stdx/ct_format.hpp index 62006ae..2e563d5 100644 --- a/include/stdx/ct_format.hpp +++ b/include/stdx/ct_format.hpp @@ -55,7 +55,7 @@ template format_result(Str) -> format_result>; inline namespace literals { inline namespace ct_string_literals { -template CONSTEVAL auto operator""_fmt_res() { +template CONSTEVAL_UDL auto operator""_fmt_res() { return format_result{cts_t{}}; } } // namespace ct_string_literals diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index d316549..7e9cfb5 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -162,9 +162,11 @@ template CONSTEVAL auto ct() { return cts_t{}; } inline namespace literals { inline namespace ct_string_literals { -template CONSTEVAL auto operator""_cts() { return S; } +template CONSTEVAL_UDL auto operator""_cts() { return S; } -template CONSTEVAL auto operator""_ctst() { return cts_t{}; } +template CONSTEVAL_UDL auto operator""_ctst() { + return cts_t{}; +} } // namespace ct_string_literals } // namespace literals } // namespace v1 diff --git a/include/stdx/tuple.hpp b/include/stdx/tuple.hpp index 9d09013..9f2501a 100644 --- a/include/stdx/tuple.hpp +++ b/include/stdx/tuple.hpp @@ -18,7 +18,7 @@ using index_constant = std::integral_constant; template constexpr static index_constant index{}; inline namespace literals { -template CONSTEVAL auto operator""_idx() { +template CONSTEVAL_UDL auto operator""_idx() { return index()>; } } // namespace literals diff --git a/include/stdx/udls.hpp b/include/stdx/udls.hpp index 22a5293..aa3a590 100644 --- a/include/stdx/udls.hpp +++ b/include/stdx/udls.hpp @@ -78,7 +78,7 @@ template using constant = std::integral_constant; template constexpr static constant _c{}; inline namespace literals { -template CONSTEVAL auto operator""_c() { +template CONSTEVAL_UDL auto operator""_c() { return _c()>; } } // namespace literals @@ -89,50 +89,52 @@ enum struct length_t : std::uint32_t {}; inline namespace literals { // NOLINTBEGIN(google-runtime-int) -CONSTEVAL auto operator""_lsb(unsigned long long int n) -> lsb_t { +CONSTEVAL_UDL auto operator""_lsb(unsigned long long int n) -> lsb_t { return static_cast(n); } -CONSTEVAL auto operator""_msb(unsigned long long int n) -> msb_t { +CONSTEVAL_UDL auto operator""_msb(unsigned long long int n) -> msb_t { return static_cast(n); } -CONSTEVAL auto operator""_len(unsigned long long int n) -> length_t { +CONSTEVAL_UDL auto operator""_len(unsigned long long int n) -> length_t { return static_cast(n); } // NOLINTEND(google-runtime-int) } // namespace literals inline namespace literals { -CONSTEVAL auto operator""_b(char const *, std::size_t) -> bool { return true; } -CONSTEVAL auto operator""_true(char const *, std::size_t) -> bool { +CONSTEVAL_UDL auto operator""_b(char const *, std::size_t) -> bool { return true; } -CONSTEVAL auto operator""_false(char const *, std::size_t) -> bool { +CONSTEVAL_UDL auto operator""_true(char const *, std::size_t) -> bool { + return true; +} +CONSTEVAL_UDL auto operator""_false(char const *, std::size_t) -> bool { return false; } // NOLINTBEGIN(google-runtime-int) -CONSTEVAL auto operator""_k(unsigned long long int n) +CONSTEVAL_UDL auto operator""_k(unsigned long long int n) -> unsigned long long int { return n * 1'000u; } -CONSTEVAL auto operator""_M(unsigned long long int n) +CONSTEVAL_UDL auto operator""_M(unsigned long long int n) -> unsigned long long int { return n * 1'000'000u; } -CONSTEVAL auto operator""_G(unsigned long long int n) +CONSTEVAL_UDL auto operator""_G(unsigned long long int n) -> unsigned long long int { return n * 1'000'000'000u; } -CONSTEVAL auto operator""_ki(unsigned long long int n) +CONSTEVAL_UDL auto operator""_ki(unsigned long long int n) -> unsigned long long int { return n * 1'024u; } -CONSTEVAL auto operator""_Mi(unsigned long long int n) +CONSTEVAL_UDL auto operator""_Mi(unsigned long long int n) -> unsigned long long int { return n * 1'024ull * 1'024ull; } -CONSTEVAL auto operator""_Gi(unsigned long long int n) +CONSTEVAL_UDL auto operator""_Gi(unsigned long long int n) -> unsigned long long int { return n * 1'024ull * 1'024ull * 1'024ull; } @@ -140,7 +142,7 @@ CONSTEVAL auto operator""_Gi(unsigned long long int n) // NOLINTBEGIN(cppcoreguidelines-macro-usage) #define STDX_SMALL_INT_LITERAL_DEF(x) \ - CONSTEVAL auto operator""_##x(char const *, std::size_t) \ + CONSTEVAL_UDL auto operator""_##x(char const *, std::size_t) \ ->std::integral_constant { \ return {}; \ }