diff --git a/include/fmt/core.h b/include/fmt/core.h index fbd9049e..a8cc2678 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -629,16 +629,18 @@ template class buffer { T* ptr_; size_t size_; size_t capacity_; + bool fixed_; protected: // Don't initialize ptr_ since it is not accessed to save a few cycles. FMT_SUPPRESS_MSC_WARNING(26495) - buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} + buffer(size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz), fixed_(false) {} - buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0) FMT_NOEXCEPT - : ptr_(p), - size_(sz), - capacity_(cap) {} + buffer(T* p = nullptr, size_t sz = 0, size_t cap = 0, + bool fixed = false) FMT_NOEXCEPT : ptr_(p), + size_(sz), + capacity_(cap), + fixed_(fixed) {} /** Sets the buffer data and capacity. */ void set(T* buf_data, size_t buf_capacity) FMT_NOEXCEPT { @@ -705,6 +707,12 @@ template class buffer { } }; +// A fixed capacity buffer. +template class fixed_buffer : buffer { + public: + fixed_buffer(T* data, size_t capacity) : buffer(data, 0, capacity, true) {} +}; + // A container-backed buffer. template class container_buffer : public buffer { diff --git a/include/fmt/format.h b/include/fmt/format.h index 4e7f6aba..e511b7a1 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -372,8 +372,10 @@ reserve(std::back_insert_iterator it, size_t n) { } template -inline checked_ptr reserve(buffer_appender it, size_t n) { - return reserve(std::back_insert_iterator>(it), n); +inline buffer_appender reserve(buffer_appender it, size_t n) { + buffer& buf = get_container(it); + buf.reserve(buf.size() + n); + return it; } template inline Iterator& reserve(Iterator& it, size_t) {