Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion include/stdx/ct_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ template <typename Str, typename Args> 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 &) {
Expand Down
9 changes: 6 additions & 3 deletions include/stdx/ct_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace detail {
template <typename T>
concept format_convertible = requires(T t) {
{ T::ct_string_convertible() } -> std::same_as<std::true_type>;
{ ct_string{t.str.value} };
{ ct_string{+t} };
};
} // namespace detail

Expand All @@ -39,7 +39,7 @@ template <std::size_t N> struct ct_string {

template <detail::format_convertible T>
// 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) {
Expand Down Expand Up @@ -78,7 +78,7 @@ template <std::size_t N> struct ct_string {
};

template <detail::format_convertible T>
ct_string(T) -> ct_string<decltype(std::declval<T>().str.value)::capacity()>;
ct_string(T) -> ct_string<decltype(+std::declval<T>())::capacity()>;

template <std::size_t N, std::size_t M>
[[nodiscard]] constexpr auto operator==(ct_string<N> const &lhs,
Expand Down Expand Up @@ -142,6 +142,9 @@ template <std::size_t N, std::size_t M>
template <ct_string S> 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 <ct_string X, ct_string Y>
Expand Down
9 changes: 9 additions & 0 deletions test/ct_string.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 <stdx::ct_string> 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>);
}