diff --git a/include/fmt/compile.h b/include/fmt/compile.h index 1a987cb0..2a0be049 100644 --- a/include/fmt/compile.h +++ b/include/fmt/compile.h @@ -178,6 +178,10 @@ template struct field { if constexpr (std::is_convertible>::value) { auto s = basic_string_view(arg); return copy(s.begin(), s.end(), out); + } else if constexpr (use_format_as::value) { + return write(out, format_as(arg)); + } else if constexpr (use_format_as_member::value) { + return write(out, formatter::format_as(arg)); } else { return write(out, arg); } diff --git a/test/compile-test.cc b/test/compile-test.cc index 5a944612..73e86f35 100644 --- a/test/compile-test.cc +++ b/test/compile-test.cc @@ -479,3 +479,13 @@ TEST(compile_test, constexpr_string_format) { EXPECT_TRUE(big); } #endif // FMT_USE_CONSTEXPR_STRING + +namespace { +struct compile_format_as_type { + int value; +}; +int format_as(compile_format_as_type f) { return f.value; } +} +TEST(compile_test, format_as) { + EXPECT_EQ("42", fmt::format(FMT_COMPILE("{}"), compile_format_as_type{42})); +} \ No newline at end of file