mirror of
https://github.com/fmtlib/fmt.git
synced 2025-11-29 22:00:09 +01:00
Make append work with fixed-size buffer
This commit is contained in:
@@ -1811,9 +1811,9 @@ OutputIt vformat_to(
|
||||
basic_format_args<buffer_context<type_identity_t<Char>>> args) {
|
||||
auto& c = detail::get_container(out);
|
||||
using container = remove_reference_t<decltype(c)>;
|
||||
typename std::conditional<
|
||||
std::is_same<container, detail::buffer<Char>>::value,
|
||||
detail::buffer<Char>&, detail::container_buffer<container>>::type buf(c);
|
||||
conditional_t<std::is_same<container, detail::buffer<Char>>::value,
|
||||
detail::buffer<Char>&, detail::container_buffer<container>>
|
||||
buf(c);
|
||||
detail::vformat_to(buf, to_string_view(format_str), args);
|
||||
return out;
|
||||
}
|
||||
|
||||
@@ -571,11 +571,15 @@ template <typename T> constexpr bool use_grisu() {
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
void buffer<T>::append(const U* begin, const U* end) {
|
||||
size_t new_size = size_ + to_unsigned(end - begin);
|
||||
try_reserve(new_size);
|
||||
std::uninitialized_copy(begin, end,
|
||||
make_checked(ptr_ + size_, capacity_ - size_));
|
||||
size_ = new_size;
|
||||
do {
|
||||
auto count = to_unsigned(end - begin);
|
||||
try_reserve(size_ + count);
|
||||
auto free_cap = capacity_ - size_;
|
||||
if (free_cap < count) count = free_cap;
|
||||
std::uninitialized_copy_n(begin, count, make_checked(ptr_ + size_, count));
|
||||
size_ += count;
|
||||
begin += count;
|
||||
} while (begin != end);
|
||||
}
|
||||
} // namespace detail
|
||||
|
||||
|
||||
Reference in New Issue
Block a user