Skip to content

Commit

Permalink
Make appender compatible with fill
Browse files Browse the repository at this point in the history
  • Loading branch information
vitaut committed Jul 19, 2024
1 parent 447c6cb commit de684ef
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
7 changes: 7 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand Down
7 changes: 7 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit de684ef

Please sign in to comment.