Make appender compatible with fill

This commit is contained in:
Victor Zverovich 2024-07-19 15:08:52 -07:00
parent 447c6cbf44
commit de684ef776
2 changed files with 14 additions and 0 deletions

View File

@ -106,6 +106,13 @@
# define FMT_NOINLINE
#endif
namespace std {
template <> struct iterator_traits<fmt::appender> {
using iterator_category = output_iterator_tag;
using value_type = char;
};
} // namespace std
#ifndef FMT_THROW
# if FMT_EXCEPTIONS
# if FMT_MSC_VERSION || defined(__NVCC__)

View File

@ -2057,6 +2057,13 @@ TEST(format_test, output_iterators) {
EXPECT_EQ("42", s.str());
}
TEST(format_test, fill_via_appender) {
fmt::memory_buffer buf;
auto it = fmt::appender(buf);
std::fill_n(it, 3, '~');
EXPECT_EQ(fmt::to_string(buf), "~~~");
}
TEST(format_test, formatted_size) {
EXPECT_EQ(2u, fmt::formatted_size("{}", 42));
EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42));