diff --git a/include/fmt/core.h b/include/fmt/core.h index 46723d59..2d8cb520 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2737,11 +2737,19 @@ FMT_FORMAT_AS(short, int); FMT_FORMAT_AS(unsigned short, unsigned); FMT_FORMAT_AS(long, long long); FMT_FORMAT_AS(unsigned long, unsigned long long); -FMT_FORMAT_AS(Char*, const Char*); FMT_FORMAT_AS(std::basic_string, basic_string_view); FMT_FORMAT_AS(std::nullptr_t, const void*); FMT_FORMAT_AS(detail::std_string_view, basic_string_view); +template +struct formatter : formatter { + template + auto format(const Char* val, FormatContext& ctx) const + -> decltype(ctx.out()) { + return formatter::format(static_cast(val), ctx); + } +}; + template struct runtime_format_string { basic_string_view str; }; diff --git a/test/format-test.cc b/test/format-test.cc index 6e8578a0..7bfd20d3 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1828,6 +1828,23 @@ TEST(format_test, join) { EXPECT_EQ("0 1 0", fmt::format("{}", join(v4, " "))); } +TEST(format_test, join_c_str) { + // { + // const char* argv[] = { "zero", "one", "two" }; + // EXPECT_EQ("(zero, one, two)", fmt::format("({})", fmt::join(argv, argv + 3, ", "))); + // } + + // { + char* argv[] = { "zero", "one", "two" }; + EXPECT_EQ("(zero, one, two)", fmt::format("({})", fmt::join(argv, argv + 3, ", "))); + // } + + { + // const char* const argv[] = { "zero", "one", "two" }; + // EXPECT_EQ("(zero, one, two)", fmt::format("({})", fmt::join(argv, argv + 3, ", "))); + } +} + #ifdef __cpp_lib_byte TEST(format_test, join_bytes) { auto v = std::vector{std::byte(1), std::byte(2), std::byte(3)};