Skip to content

Commit

Permalink
Make buffer_appender default-constructible when back_insert_iterator is
Browse files Browse the repository at this point in the history
  • Loading branch information
randomnetcat authored and vitaut committed Apr 1, 2021
1 parent 0d6b70d commit c62e4c3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 1 addition & 1 deletion include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -877,7 +877,7 @@ class buffer_appender : public std::back_insert_iterator<buffer<T>> {
using base = std::back_insert_iterator<buffer<T>>;

public:
explicit buffer_appender(buffer<T>& buf) : base(buf) {}
using std::back_insert_iterator<buffer<T>>::back_insert_iterator;
buffer_appender(base it) : base(it) {}

buffer_appender& operator++() {
Expand Down
17 changes: 17 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,23 @@ static void check_move_buffer(
EXPECT_EQ(alloc, buffer2.get_allocator().get());
}

TEST(BufferAppenderTest, BufferAppenderDefaultConstruct) {
// back_insert_iterator is not default-constructible before C++20, so
// buffer_appender can only be default-constructible when back_insert_iterator
// is.
static_assert(
std::is_default_constructible<
std::back_insert_iterator<fmt::detail::buffer<char>>>::value ==
std::is_default_constructible<fmt::detail::buffer_appender<char>>::value,
"");
}

#ifdef __cpp_lib_ranges
TEST(BufferAppenderTest, BufferAppenderOutputIterator) {
static_assert(std::output_iterator<fmt::detail::buffer_appender<char>, char>);
}
#endif

TEST(MemoryBufferTest, MoveCtorInlineBuffer) {
std::allocator<char> alloc;
basic_memory_buffer<char, 5, std_allocator> buffer((std_allocator(&alloc)));
Expand Down

0 comments on commit c62e4c3

Please sign in to comment.