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
6 changes: 3 additions & 3 deletions include/stdx/ct_format.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -235,12 +235,12 @@ consteval auto arg_value(std::integral_constant<T, V>) {
if constexpr (std::is_enum_v<T>) {
return enum_as_string<V>();
} else {
return V;
return expand(V);
}
}

template <typename T> consteval auto arg_value(type_identity<T>) {
return type_as_string<T>();
return type_as_string<expand_t<T>>();
}

template <ct_string S> consteval auto arg_value(cts_t<S>) { return S; }
Expand All @@ -255,7 +255,7 @@ consteval auto arg_value(fmt_cx_value auto a) {
} else if constexpr (std::is_enum_v<decltype(a())>) {
return enum_as_string<a()>();
} else {
return a();
return expand(a());
}
}

Expand Down
25 changes: 25 additions & 0 deletions test/ct_format.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ TEST_CASE("format a compile-time stringish argument (CX_VALUE)",
"Hello world"_fmt_res);
}

TEST_CASE("format a shrunk compile-time stringish argument (CX_VALUE)",
"[ct_format]") {
using namespace std::string_view_literals;
STATIC_REQUIRE(stdx::ct_format<"Hello {}">(CX_VALUE(
stdx::shrink<"world">())) == "Hello world"_fmt_res);
}

TEST_CASE("format a compile-time stringish argument (ct)", "[ct_format]") {
using namespace std::string_view_literals;
STATIC_REQUIRE(stdx::ct_format<"Hello {}">("world"_ctst) ==
Expand All @@ -76,6 +83,14 @@ TEST_CASE("format a compile-time stringish argument (ct)", "[ct_format]") {
"Hello world"_fmt_res);
}

TEST_CASE("format a shrunk compile-time stringish argument (ct)",
"[ct_format]") {
using namespace std::string_view_literals;
STATIC_REQUIRE(
stdx::ct_format<"Hello {}">(stdx::ct<stdx::shrink<"world">()>()) ==
"Hello world"_fmt_res);
}

TEST_CASE("format a compile-time integral argument (CX_VALUE)", "[ct_format]") {
STATIC_REQUIRE(stdx::ct_format<"Hello {}">(CX_VALUE(42)) ==
"Hello 42"_fmt_res);
Expand Down Expand Up @@ -139,11 +154,21 @@ TEST_CASE("format a type argument (CX_VALUE)", "[ct_format]") {
"Hello int"_fmt_res);
}

TEST_CASE("format a shrunk type argument (CX_VALUE)", "[ct_format]") {
STATIC_REQUIRE(stdx::ct_format<"Hello {}">(CX_VALUE(stdx::shrink_t<int>)) ==
"Hello int"_fmt_res);
}

TEST_CASE("format a type argument (ct)", "[ct_format]") {
STATIC_REQUIRE(stdx::ct_format<"Hello {}">(stdx::ct<int>()) ==
"Hello int"_fmt_res);
}

TEST_CASE("format a shrunk type argument (ct)", "[ct_format]") {
STATIC_REQUIRE(stdx::ct_format<"Hello {}">(
stdx::ct<stdx::shrink_t<int>>()) == "Hello int"_fmt_res);
}

TEST_CASE("format a compile-time argument with different base", "[ct_format]") {
STATIC_REQUIRE(stdx::ct_format<"Hello 0x{:x}">(CX_VALUE(42)) ==
"Hello 0x2a"_fmt_res);
Expand Down