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
18 changes: 18 additions & 0 deletions include/stdx/ct_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ template <typename Str, typename Args> struct format_result {
format_result const &) -> bool = default;
};

template <typename Str, typename Args>
requires(Args::size() == 0 and is_cx_value_v<Str>)
struct format_result<Str, Args> {
CONSTEVAL static auto ct_string_convertible() -> std::true_type;

[[no_unique_address]] Str str;
[[no_unique_address]] Args args{};

friend constexpr auto operator+(format_result const &fr) { return +fr.str; }

constexpr auto operator()() const noexcept { return +(*this); }
using cx_value_t [[maybe_unused]] = void;

private:
friend constexpr auto operator==(format_result const &,
format_result const &) -> bool = default;
};

template <typename Str, typename Args>
format_result(Str, Args) -> format_result<Str, Args>;
template <typename Str> format_result(Str) -> format_result<Str, tuple<>>;
Expand Down
2 changes: 2 additions & 0 deletions include/stdx/ct_string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,8 @@ template <ct_string S> struct cts_t {

CONSTEVAL static auto ct_string_convertible() -> std::true_type;
friend constexpr auto operator+(cts_t const &) { return value; }
constexpr auto operator()() const noexcept { return value; }
using cx_value_t [[maybe_unused]] = void;
};

template <ct_string X, ct_string Y>
Expand Down
1 change: 0 additions & 1 deletion include/stdx/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,5 @@ STDX_PRAGMA(diagnostic pop)
template <typename T, typename = void> constexpr auto is_complete_v = false;
template <typename T>
constexpr auto is_complete_v<T, detail::void_v<sizeof(T)>> = true;

} // namespace v1
} // namespace stdx
12 changes: 11 additions & 1 deletion test/ct_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,11 +263,21 @@ TEST_CASE("FORMAT a type argument", "[ct_format]") {
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", int) == "Hello int"_fmt_res);
}

TEST_CASE("FORMAT a constexpr string argument", "[ct_format]") {
TEST_CASE("FORMAT a constexpr ct_string argument", "[ct_format]") {
constexpr static auto S = "world"_cts;
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", S) == "Hello world"_fmt_res);
}

TEST_CASE("FORMAT a cts_t argument", "[ct_format]") {
auto S = "world"_ctst;
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", S) == "Hello world"_fmt_res);
}

TEST_CASE("FORMAT a format_result argument", "[ct_format]") {
auto S = "world"_fmt_res;
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", S) == "Hello world"_fmt_res);
}

TEST_CASE("FORMAT a constexpr int argument", "[ct_format]") {
constexpr static auto I = 17;
STATIC_REQUIRE(STDX_CT_FORMAT("Hello {}", I) == "Hello 17"_fmt_res);
Expand Down