diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 94407af..0efd5f2 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -3,6 +3,7 @@ #if __cplusplus >= 202002L #include +#include #include #include @@ -128,6 +129,10 @@ constexpr auto operator+(cts_t, cts_t) { return cts_t{}; } +namespace detail { +template struct ct_helper>; +} // namespace detail + template CONSTEVAL auto ct() { return cts_t{}; } inline namespace literals { diff --git a/include/stdx/utility.hpp b/include/stdx/utility.hpp index cdb3d27..c138b96 100644 --- a/include/stdx/utility.hpp +++ b/include/stdx/utility.hpp @@ -193,10 +193,23 @@ constexpr auto is_aligned_with = [](auto v) -> bool { } }; -template CONSTEVAL auto ct() { - return std::integral_constant{}; +#if __cplusplus >= 202002L + +namespace detail { +template struct ct_helper { + // NOLINTNEXTLINE(google-explicit-constructor) + CONSTEVAL ct_helper(T t) : value(t) {} + T value; +}; +template ct_helper(T) -> ct_helper; +} // namespace detail + +template CONSTEVAL auto ct() { + return std::integral_constant{}; } template CONSTEVAL auto ct() { return type_identity{}; } + +#endif } // namespace v1 } // namespace stdx diff --git a/test/ct_string.cpp b/test/ct_string.cpp index 878e38b..f7f44c5 100644 --- a/test/ct_string.cpp +++ b/test/ct_string.cpp @@ -139,6 +139,8 @@ TEST_CASE("wrap ct_string in type", "[ct_string]") { TEST_CASE("ct (ct_string)", "[ct_string]") { using namespace stdx::ct_string_literals; - constexpr auto v = stdx::ct<"Hello">(); - static_assert(v == "Hello"_ctst); + constexpr auto v1 = stdx::ct<"Hello">(); + static_assert(v1 == "Hello"_ctst); + constexpr auto v2 = stdx::ct<"Hello"_cts>(); + static_assert(v2 == "Hello"_ctst); } diff --git a/test/utility.cpp b/test/utility.cpp index 6759c68..c13b48c 100644 --- a/test/utility.cpp +++ b/test/utility.cpp @@ -204,6 +204,8 @@ TEST_CASE("is_aligned_with (pointer)", "[utility]") { CHECK(stdx::is_aligned_with(p)); } +#if __cplusplus >= 202002L + TEST_CASE("ct (integral)", "[utility]") { constexpr auto vs = stdx::ct<42>(); static_assert( @@ -239,3 +241,5 @@ TEST_CASE("ct (type)", "[utility]") { constexpr auto v = stdx::ct(); static_assert(std::is_same_v const>); } + +#endif