mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-02 11:28:20 +00:00
Move cstddef include to format.cc and refactor Buffer::append
This commit is contained in:
parent
3df9bf3a91
commit
7dcf05108e
@ -34,6 +34,7 @@
|
||||
#include <climits>
|
||||
#include <cmath>
|
||||
#include <cstdarg>
|
||||
#include <cstddef> // for std::ptrdiff_t
|
||||
|
||||
#if defined(_WIN32) && defined(__MINGW32__)
|
||||
# include <cstring>
|
||||
@ -1040,10 +1041,10 @@ void fmt::internal::PrintfFormatter<Char>::format(
|
||||
ArgConverter<intmax_t>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 'z':
|
||||
ArgConverter<size_t>(arg, *s).visit(arg);
|
||||
ArgConverter<std::size_t>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 't':
|
||||
ArgConverter<ptrdiff_t>(arg, *s).visit(arg);
|
||||
ArgConverter<std::ptrdiff_t>(arg, *s).visit(arg);
|
||||
break;
|
||||
case 'L':
|
||||
// printf produces garbage when 'L' is omitted for long double, no
|
||||
|
10
format.h
10
format.h
@ -32,7 +32,6 @@
|
||||
|
||||
#include <cassert>
|
||||
#include <cmath>
|
||||
#include <cstddef> // for std::ptrdiff_t
|
||||
#include <cstdio>
|
||||
#include <algorithm>
|
||||
#include <limits>
|
||||
@ -484,11 +483,12 @@ class Buffer {
|
||||
template <typename T>
|
||||
template <typename U>
|
||||
void Buffer<T>::append(const U *begin, const U *end) {
|
||||
std::ptrdiff_t num_elements = end - begin;
|
||||
if (size_ + num_elements > capacity_)
|
||||
grow(size_ + num_elements);
|
||||
assert(begin <= end);
|
||||
std::size_t new_size = size_ + (end - begin);
|
||||
if (new_size > capacity_)
|
||||
grow(new_size);
|
||||
std::copy(begin, end, internal::make_ptr(ptr_, capacity_) + size_);
|
||||
size_ += num_elements;
|
||||
size_ = new_size;
|
||||
}
|
||||
|
||||
namespace internal {
|
||||
|
Loading…
Reference in New Issue
Block a user