diff --git a/include/stdx/ct_format.hpp b/include/stdx/ct_format.hpp index 2e563d5..24df3ce 100644 --- a/include/stdx/ct_format.hpp +++ b/include/stdx/ct_format.hpp @@ -35,7 +35,7 @@ template struct format_result { friend constexpr auto operator+(format_result const &fr) requires(decltype(ct_string_convertible())::value) { - return ct_string{fr.str.value}; + return +fr.str; } friend constexpr auto operator+(format_result const &) { diff --git a/include/stdx/ct_string.hpp b/include/stdx/ct_string.hpp index 7e9cfb5..5f6566d 100644 --- a/include/stdx/ct_string.hpp +++ b/include/stdx/ct_string.hpp @@ -22,7 +22,7 @@ namespace detail { template concept format_convertible = requires(T t) { { T::ct_string_convertible() } -> std::same_as; - { ct_string{t.str.value} }; + { ct_string{+t} }; }; } // namespace detail @@ -39,7 +39,7 @@ template struct ct_string { template // NOLINTNEXTLINE(google-explicit-constructor) - CONSTEVAL explicit(false) ct_string(T t) : ct_string(t.str.value) {} + CONSTEVAL explicit(false) ct_string(T t) : ct_string(+t) {} CONSTEVAL explicit(true) ct_string(char const *str, std::size_t sz) { for (auto i = std::size_t{}; i < sz; ++i) { @@ -78,7 +78,7 @@ template struct ct_string { }; template -ct_string(T) -> ct_string().str.value)::capacity()>; +ct_string(T) -> ct_string())::capacity()>; template [[nodiscard]] constexpr auto operator==(ct_string const &lhs, @@ -142,6 +142,9 @@ template template struct cts_t { using value_type = decltype(S); constexpr static auto value = S; + + CONSTEVAL static auto ct_string_convertible() -> std::true_type; + friend constexpr auto operator+(cts_t const &) { return value; } }; template diff --git a/test/ct_string.cpp b/test/ct_string.cpp index 80d0b8d..666da69 100644 --- a/test/ct_string.cpp +++ b/test/ct_string.cpp @@ -150,3 +150,12 @@ TEST_CASE("ct (ct_string)", "[ct_string]") { constexpr auto v2 = stdx::ct<"Hello"_cts>(); STATIC_REQUIRE(v2 == "Hello"_ctst); } + +namespace { +template constexpr auto conversion_success = true; +} // namespace + +TEST_CASE("cts_t can implicitly convert to ct_string", "[ct_string]") { + using namespace stdx::ct_string_literals; + STATIC_REQUIRE(conversion_success<"Hello"_ctst>); +}