Make buffer_appender default-constructible when back_insert_iterator is

This commit is contained in:
Jason Cobb 2021-03-31 14:06:48 -04:00 committed by Victor Zverovich
parent 0d6b70d96b
commit c62e4c30f4
2 changed files with 18 additions and 1 deletions

View File

@ -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++() {

View File

@ -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)));