mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 10:47:35 +02:00
Use standard context in print
This commit is contained in:
@ -524,9 +524,9 @@ FMT_CONSTEXPR20 auto formatted_size(const S& fmt, const Args&... args)
|
|||||||
template <typename S, typename... Args,
|
template <typename S, typename... Args,
|
||||||
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
FMT_ENABLE_IF(detail::is_compiled_string<S>::value)>
|
||||||
void print(std::FILE* f, const S& fmt, const Args&... args) {
|
void print(std::FILE* f, const S& fmt, const Args&... args) {
|
||||||
memory_buffer buffer;
|
auto buf = memory_buffer();
|
||||||
fmt::format_to(std::back_inserter(buffer), fmt, args...);
|
fmt::format_to(appender(buf), fmt, args...);
|
||||||
detail::print(f, {buffer.data(), buffer.size()});
|
detail::print(f, {buf.data(), buf.size()});
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename S, typename... Args,
|
template <typename S, typename... Args,
|
||||||
|
@ -265,11 +265,23 @@ TEST(compile_test, to_string_and_formatter) {
|
|||||||
fmt::format(FMT_COMPILE("{}"), to_stringable());
|
fmt::format(FMT_COMPILE("{}"), to_stringable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct std_context_test {};
|
||||||
|
|
||||||
|
FMT_BEGIN_NAMESPACE
|
||||||
|
template <> struct formatter<std_context_test> : formatter<int> {
|
||||||
|
auto format(std_context_test, format_context& ctx) const
|
||||||
|
-> decltype(ctx.out()) {
|
||||||
|
return ctx.out();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
FMT_END_NAMESPACE
|
||||||
|
|
||||||
TEST(compile_test, print) {
|
TEST(compile_test, print) {
|
||||||
EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"),
|
EXPECT_WRITE(stdout, fmt::print(FMT_COMPILE("Don't {}!"), "panic"),
|
||||||
"Don't panic!");
|
"Don't panic!");
|
||||||
EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"),
|
EXPECT_WRITE(stderr, fmt::print(stderr, FMT_COMPILE("Don't {}!"), "panic"),
|
||||||
"Don't panic!");
|
"Don't panic!");
|
||||||
|
fmt::print(FMT_COMPILE("{}"), std_context_test());
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user