Fix detail::write with fallback formatter (#1829)
* add support for fallback_formatter in detail::write * add ToString test into OStreamTest to check fmt::to_string() with class that has output stream operator * add WithOstreamOperator test into CompileTest to check fmt::format() with FMT_COMPILE() and class that has output stream operator * use conditional_t inside detail::write instead of 2 overloads * Revert "add WithOstreamOperator test into CompileTest" * remove Context from template parameters in detail::write
This commit is contained in:
parent
06895a7687
commit
1651b2d433
@ -1847,8 +1847,13 @@ auto write(OutputIt out, const T& value) -> typename std::enable_if<
|
||||
mapped_type_constant<T, basic_format_context<OutputIt, Char>>::value ==
|
||||
type::custom_type,
|
||||
OutputIt>::type {
|
||||
basic_format_context<OutputIt, Char> ctx(out, {}, {});
|
||||
return formatter<T>().format(value, ctx);
|
||||
using context_type = basic_format_context<OutputIt, Char>;
|
||||
using formatter_type =
|
||||
conditional_t<has_formatter<T, context_type>::value,
|
||||
typename context_type::template formatter_type<T>,
|
||||
fallback_formatter<T, Char>>;
|
||||
context_type ctx(out, {}, {});
|
||||
return formatter_type().format(value, ctx);
|
||||
}
|
||||
|
||||
// An argument visitor that formats the argument and writes it via the output
|
||||
|
@ -319,3 +319,7 @@ TEST(OStreamTest, CopyFmt) {
|
||||
TEST(OStreamTest, CompileTimeString) {
|
||||
EXPECT_EQ("42", fmt::format(FMT_STRING("{}"), 42));
|
||||
}
|
||||
|
||||
TEST(OStreamTest, ToString) {
|
||||
EXPECT_EQ("ABC", fmt::to_string(fmt_test::ABC()));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user