basic_buffer -> buffer

This reduces symbol sizes and gets rid of shadowing warnings.
This commit is contained in:
Victor Zverovich
2019-04-07 10:05:49 -07:00
parent 6e37c20030
commit 2808395481
14 changed files with 100 additions and 101 deletions

View File

@ -241,10 +241,10 @@ FMT_CONSTEXPR typename std::make_unsigned<Int>::type to_unsigned(Int value) {
} }
/** A contiguous memory buffer with an optional growing ability. */ /** A contiguous memory buffer with an optional growing ability. */
template <typename T> class basic_buffer { template <typename T> class buffer {
private: private:
basic_buffer(const basic_buffer&) = delete; buffer(const buffer&) = delete;
void operator=(const basic_buffer&) = delete; void operator=(const buffer&) = delete;
T* ptr_; T* ptr_;
std::size_t size_; std::size_t size_;
@ -252,12 +252,12 @@ template <typename T> class basic_buffer {
protected: protected:
// Don't initialize ptr_ since it is not accessed to save a few cycles. // Don't initialize ptr_ since it is not accessed to save a few cycles.
basic_buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {} buffer(std::size_t sz) FMT_NOEXCEPT : size_(sz), capacity_(sz) {}
basic_buffer(T* p = FMT_NULL, std::size_t sz = 0, buffer(T* p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
std::size_t cap = 0) FMT_NOEXCEPT : ptr_(p), : ptr_(p),
size_(sz), size_(sz),
capacity_(cap) {} capacity_(cap) {}
/** Sets the buffer data and capacity. */ /** Sets the buffer data and capacity. */
void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT { void set(T* buf_data, std::size_t buf_capacity) FMT_NOEXCEPT {
@ -272,7 +272,7 @@ template <typename T> class basic_buffer {
typedef T value_type; typedef T value_type;
typedef const T& const_reference; typedef const T& const_reference;
virtual ~basic_buffer() {} virtual ~buffer() {}
T* begin() FMT_NOEXCEPT { return ptr_; } T* begin() FMT_NOEXCEPT { return ptr_; }
T* end() FMT_NOEXCEPT { return ptr_ + size_; } T* end() FMT_NOEXCEPT { return ptr_ + size_; }
@ -317,12 +317,9 @@ template <typename T> class basic_buffer {
const T& operator[](std::size_t index) const { return ptr_[index]; } const T& operator[](std::size_t index) const { return ptr_[index]; }
}; };
typedef basic_buffer<char> buffer;
typedef basic_buffer<wchar_t> wbuffer;
// A container-backed buffer. // A container-backed buffer.
template <typename Container> template <typename Container>
class container_buffer : public basic_buffer<typename Container::value_type> { class container_buffer : public buffer<typename Container::value_type> {
private: private:
Container& container_; Container& container_;
@ -334,7 +331,7 @@ class container_buffer : public basic_buffer<typename Container::value_type> {
public: public:
explicit container_buffer(Container& c) explicit container_buffer(Container& c)
: basic_buffer<typename Container::value_type>(c.size()), container_(c) {} : buffer<typename Container::value_type>(c.size()), container_(c) {}
}; };
// Extracts a reference to the container from back_insert_iterator. // Extracts a reference to the container from back_insert_iterator.
@ -1141,7 +1138,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
template <typename Char> struct buffer_context { template <typename Char> struct buffer_context {
typedef basic_format_context< typedef basic_format_context<
std::back_insert_iterator<internal::basic_buffer<Char>>, Char> std::back_insert_iterator<internal::buffer<Char>>, Char>
type; type;
}; };
typedef buffer_context<char>::type format_context; typedef buffer_context<char>::type format_context;
@ -1381,7 +1378,7 @@ std::basic_string<Char> vformat(
template <typename Char> template <typename Char>
typename buffer_context<Char>::type::iterator vformat_to( typename buffer_context<Char>::type::iterator vformat_to(
internal::basic_buffer<Char>& buf, basic_string_view<Char> format_str, internal::buffer<Char>& buf, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args); basic_format_args<typename buffer_context<Char>::type> args);
} // namespace internal } // namespace internal
@ -1415,7 +1412,7 @@ template <typename Char>
struct is_contiguous<std::basic_string<Char>> : std::true_type {}; struct is_contiguous<std::basic_string<Char>> : std::true_type {};
template <typename Char> template <typename Char>
struct is_contiguous<internal::basic_buffer<Char>> : std::true_type {}; struct is_contiguous<internal::buffer<Char>> : std::true_type {};
/** Formats a string and writes the output to ``out``. */ /** Formats a string and writes the output to ``out``. */
template <typename Container, typename S> template <typename Container, typename S>

View File

@ -85,7 +85,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) {
# define FMT_SWPRINTF swprintf # define FMT_SWPRINTF swprintf
#endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT) #endif // defined(_WIN32) && defined(__MINGW32__) && !defined(__NO_ISOCEXT)
typedef void (*FormatFunc)(internal::buffer&, int, string_view); typedef void (*FormatFunc)(internal::buffer<char>&, int, string_view);
// Portable thread-safe version of strerror. // Portable thread-safe version of strerror.
// Sets buffer to point to a string describing the error code. // Sets buffer to point to a string describing the error code.
@ -154,7 +154,7 @@ int safe_strerror(int error_code, char*& buffer,
return dispatcher(error_code, buffer, buffer_size).run(); return dispatcher(error_code, buffer, buffer_size).run();
} }
void format_error_code(internal::buffer& out, int error_code, void format_error_code(internal::buffer<char>& out, int error_code,
string_view message) FMT_NOEXCEPT { string_view message) FMT_NOEXCEPT {
// Report error code making sure that the output fits into // Report error code making sure that the output fits into
// inline_buffer_size to avoid dynamic memory allocation and potential // inline_buffer_size to avoid dynamic memory allocation and potential
@ -661,7 +661,7 @@ struct shortest_handler {
template <typename Double, typename std::enable_if< template <typename Double, typename std::enable_if<
sizeof(Double) == sizeof(uint64_t), int>::type> sizeof(Double) == sizeof(uint64_t), int>::type>
FMT_FUNC bool grisu2_format(Double value, buffer& buf, int precision, FMT_FUNC bool grisu2_format(Double value, buffer<char>& buf, int precision,
bool fixed, int& exp) { bool fixed, int& exp) {
FMT_ASSERT(value >= 0, "value is negative"); FMT_ASSERT(value >= 0, "value is negative");
if (value <= 0) { // <= instead of == to silence a warning. if (value <= 0) { // <= instead of == to silence a warning.
@ -713,7 +713,7 @@ FMT_FUNC bool grisu2_format(Double value, buffer& buf, int precision,
} }
template <typename Double> template <typename Double>
void sprintf_format(Double value, internal::buffer& buf, void sprintf_format(Double value, internal::buffer<char>& buf,
core_format_specs spec) { core_format_specs spec) {
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail. // Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
FMT_ASSERT(buf.capacity() != 0, "empty buffer"); FMT_ASSERT(buf.capacity() != 0, "empty buffer");
@ -849,7 +849,7 @@ FMT_FUNC void windows_error::init(int err_code, string_view format_str,
base = std::runtime_error(to_string(buffer)); base = std::runtime_error(to_string(buffer));
} }
FMT_FUNC void internal::format_windows_error(internal::buffer& out, FMT_FUNC void internal::format_windows_error(internal::buffer<char>& out,
int error_code, int error_code,
string_view message) FMT_NOEXCEPT { string_view message) FMT_NOEXCEPT {
FMT_TRY { FMT_TRY {
@ -883,7 +883,7 @@ FMT_FUNC void internal::format_windows_error(internal::buffer& out,
#endif // FMT_USE_WINDOWS_H #endif // FMT_USE_WINDOWS_H
FMT_FUNC void format_system_error(internal::buffer& out, int error_code, FMT_FUNC void format_system_error(internal::buffer<char>& out, int error_code,
string_view message) FMT_NOEXCEPT { string_view message) FMT_NOEXCEPT {
FMT_TRY { FMT_TRY {
memory_buffer buf; memory_buffer buf;

View File

@ -352,8 +352,8 @@ class back_insert_range
back_insert_range(typename base::iterator it) : base(it) {} back_insert_range(typename base::iterator it) : base(it) {}
}; };
typedef basic_writer<back_insert_range<internal::buffer>> writer; typedef basic_writer<back_insert_range<internal::buffer<char>>> writer;
typedef basic_writer<back_insert_range<internal::wbuffer>> wwriter; typedef basic_writer<back_insert_range<internal::buffer<wchar_t>>> wwriter;
/** A formatting error such as invalid format string. */ /** A formatting error such as invalid format string. */
class format_error : public std::runtime_error { class format_error : public std::runtime_error {
@ -383,7 +383,7 @@ template <typename T> inline T* make_checked(T* p, std::size_t) { return p; }
template <typename T> template <typename T>
template <typename U> template <typename U>
void basic_buffer<T>::append(const U* begin, const U* end) { void buffer<T>::append(const U* begin, const U* end) {
std::size_t new_size = size_ + internal::to_unsigned(end - begin); std::size_t new_size = size_ + internal::to_unsigned(end - begin);
reserve(new_size); reserve(new_size);
std::uninitialized_copy(begin, end, std::uninitialized_copy(begin, end,
@ -454,8 +454,7 @@ enum { inline_buffer_size = 500 };
*/ */
template <typename T, std::size_t SIZE = inline_buffer_size, template <typename T, std::size_t SIZE = inline_buffer_size,
typename Allocator = std::allocator<T>> typename Allocator = std::allocator<T>>
class basic_memory_buffer : private Allocator, class basic_memory_buffer : private Allocator, public internal::buffer<T> {
public internal::basic_buffer<T> {
private: private:
T store_[SIZE]; T store_[SIZE];
@ -1087,7 +1086,8 @@ class utf16_to_utf8 {
FMT_API int convert(wstring_view s); FMT_API int convert(wstring_view s);
}; };
FMT_API void format_windows_error(fmt::internal::buffer& out, int error_code, FMT_API void format_windows_error(fmt::internal::buffer<char>& out,
int error_code,
fmt::string_view message) FMT_NOEXCEPT; fmt::string_view message) FMT_NOEXCEPT;
#endif #endif
@ -1149,10 +1149,10 @@ namespace internal {
// Formats value using Grisu2 algorithm: // Formats value using Grisu2 algorithm:
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf // https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))> template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
FMT_API bool grisu2_format(Double value, buffer& buf, int precision, bool fixed, FMT_API bool grisu2_format(Double value, buffer<char>& buf, int precision,
int& exp); bool fixed, int& exp);
template <typename Double, FMT_ENABLE_IF(sizeof(Double) != sizeof(uint64_t))> template <typename Double, FMT_ENABLE_IF(sizeof(Double) != sizeof(uint64_t))>
inline bool grisu2_format(Double, buffer&, int, bool, int&) { inline bool grisu2_format(Double, buffer<char>&, int, bool, int&) {
return false; return false;
} }
@ -1242,7 +1242,7 @@ It grisu2_prettify(const char* digits, int size, int exp, It it,
} }
template <typename Double> template <typename Double>
void sprintf_format(Double, internal::buffer&, core_format_specs); void sprintf_format(Double, internal::buffer<char>&, core_format_specs);
template <typename Handler> template <typename Handler>
FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) { FMT_CONSTEXPR void handle_int_type_spec(char spec, Handler&& handler) {
@ -2405,7 +2405,7 @@ class system_error : public std::runtime_error {
may look like "Unknown error -1" and is platform-dependent. may look like "Unknown error -1" and is platform-dependent.
\endrst \endrst
*/ */
FMT_API void format_system_error(internal::buffer& out, int error_code, FMT_API void format_system_error(internal::buffer<char>& out, int error_code,
fmt::string_view message) FMT_NOEXCEPT; fmt::string_view message) FMT_NOEXCEPT;
/** /**
@ -2654,7 +2654,7 @@ template <typename Range> class basic_writer {
struct double_writer { struct double_writer {
char sign; char sign;
internal::buffer& buffer; internal::buffer<char>& buffer;
size_t size() const { return buffer.size() + (sign ? 1 : 0); } size_t size() const { return buffer.size() + (sign ? 1 : 0); }
size_t width() const { return size(); } size_t width() const { return size(); }
@ -2667,14 +2667,14 @@ template <typename Range> class basic_writer {
class grisu_writer { class grisu_writer {
private: private:
internal::buffer& digits_; internal::buffer<char>& digits_;
size_t size_; size_t size_;
char sign_; char sign_;
int exp_; int exp_;
internal::gen_digits_params params_; internal::gen_digits_params params_;
public: public:
grisu_writer(char sign, internal::buffer& digits, int exp, grisu_writer(char sign, internal::buffer<char>& digits, int exp,
const internal::gen_digits_params& params) const internal::gen_digits_params& params)
: digits_(digits), sign_(sign), exp_(exp), params_(params) { : digits_(digits), sign_(sign), exp_(exp), params_(params) {
int num_digits = static_cast<int>(digits.size()); int num_digits = static_cast<int>(digits.size());
@ -3392,9 +3392,9 @@ std::basic_string<Char> to_string(const basic_memory_buffer<Char, SIZE>& buf) {
template <typename Char> template <typename Char>
typename buffer_context<Char>::type::iterator internal::vformat_to( typename buffer_context<Char>::type::iterator internal::vformat_to(
internal::basic_buffer<Char>& buf, basic_string_view<Char> format_str, internal::buffer<Char>& buf, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<typename buffer_context<Char>::type> args) {
typedef back_insert_range<internal::basic_buffer<Char>> range; typedef back_insert_range<internal::buffer<Char>> range;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str),
args); args);
} }
@ -3402,7 +3402,7 @@ typename buffer_context<Char>::type::iterator internal::vformat_to(
template <typename S, typename Char = FMT_CHAR(S), template <typename S, typename Char = FMT_CHAR(S),
FMT_ENABLE_IF(internal::is_string<S>::value)> FMT_ENABLE_IF(internal::is_string<S>::value)>
inline typename buffer_context<Char>::type::iterator vformat_to( inline typename buffer_context<Char>::type::iterator vformat_to(
internal::basic_buffer<Char>& buf, const S& format_str, internal::buffer<Char>& buf, const S& format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<typename buffer_context<Char>::type> args) {
return internal::vformat_to(buf, to_string_view(format_str), args); return internal::vformat_to(buf, to_string_view(format_str), args);
} }

View File

@ -16,10 +16,10 @@ FMT_BEGIN_NAMESPACE
namespace internal { namespace internal {
template <typename Char> template <typename Char>
typename buffer_context<Char>::type::iterator vformat_to( typename buffer_context<Char>::type::iterator vformat_to(
const std::locale& loc, basic_buffer<Char>& buf, const std::locale& loc, buffer<Char>& buf,
basic_string_view<Char> format_str, basic_string_view<Char> format_str,
basic_format_args<typename buffer_context<Char>::type> args) { basic_format_args<typename buffer_context<Char>::type> args) {
typedef back_insert_range<basic_buffer<Char>> range; typedef back_insert_range<buffer<Char>> range;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args, return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
internal::locale_ref(loc)); internal::locale_ref(loc));
} }

View File

@ -19,10 +19,10 @@ template <class Char> class formatbuf : public std::basic_streambuf<Char> {
typedef typename std::basic_streambuf<Char>::int_type int_type; typedef typename std::basic_streambuf<Char>::int_type int_type;
typedef typename std::basic_streambuf<Char>::traits_type traits_type; typedef typename std::basic_streambuf<Char>::traits_type traits_type;
basic_buffer<Char>& buffer_; buffer<Char>& buffer_;
public: public:
formatbuf(basic_buffer<Char>& buffer) : buffer_(buffer) {} formatbuf(buffer<Char>& buffer) : buffer_(buffer) {}
protected: protected:
// The put-area is actually always empty. This makes the implementation // The put-area is actually always empty. This makes the implementation
@ -71,7 +71,7 @@ template <typename T, typename Char> class is_streamable {
// Write the content of buf to os. // Write the content of buf to os.
template <typename Char> template <typename Char>
void write(std::basic_ostream<Char>& os, basic_buffer<Char>& buf) { void write(std::basic_ostream<Char>& os, buffer<Char>& buf) {
const Char* data = buf.data(); const Char* data = buf.data();
typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize; typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize;
UnsignedStreamSize size = buf.size(); UnsignedStreamSize size = buf.size();
@ -86,7 +86,7 @@ void write(std::basic_ostream<Char>& os, basic_buffer<Char>& buf) {
} }
template <typename Char, typename T> template <typename Char, typename T>
void format_value(basic_buffer<Char>& buffer, const T& value) { void format_value(buffer<Char>& buffer, const T& value) {
internal::formatbuf<Char> format_buf(buffer); internal::formatbuf<Char> format_buf(buffer);
std::basic_ostream<Char> output(&format_buf); std::basic_ostream<Char> output(&format_buf);
output.exceptions(std::ios_base::failbit | std::ios_base::badbit); output.exceptions(std::ios_base::failbit | std::ios_base::badbit);

View File

@ -216,7 +216,7 @@ class prepared_format {
std::basic_string<char_type> format(const Args&... args) const { std::basic_string<char_type> format(const Args&... args) const {
basic_memory_buffer<char_type> buffer; basic_memory_buffer<char_type> buffer;
typedef back_insert_range<internal::basic_buffer<char_type>> range; typedef back_insert_range<internal::buffer<char_type>> range;
this->vformat_to(range(buffer), make_args_checked(format_, args...)); this->vformat_to(range(buffer), make_args_checked(format_, args...));
return to_string(buffer); return to_string(buffer);
} }
@ -225,7 +225,7 @@ class prepared_format {
inline std::back_insert_iterator<Container> format_to( inline std::back_insert_iterator<Container> format_to(
std::back_insert_iterator<Container> out, const Args&... args) const { std::back_insert_iterator<Container> out, const Args&... args) const {
internal::container_buffer<Container> buffer(internal::get_container(out)); internal::container_buffer<Container> buffer(internal::get_container(out));
typedef back_insert_range<internal::basic_buffer<char_type>> range; typedef back_insert_range<internal::buffer<char_type>> range;
this->vformat_to(range(buffer), make_args_checked(format_, args...)); this->vformat_to(range(buffer), make_args_checked(format_, args...));
return out; return out;
} }
@ -241,7 +241,7 @@ class prepared_format {
template <std::size_t SIZE = inline_buffer_size> template <std::size_t SIZE = inline_buffer_size>
inline typename buffer_context<char_type>::type::iterator format_to( inline typename buffer_context<char_type>::type::iterator format_to(
basic_memory_buffer<char_type, SIZE>& buf, const Args&... args) const { basic_memory_buffer<char_type, SIZE>& buf, const Args&... args) const {
typedef back_insert_range<internal::basic_buffer<char_type>> range; typedef back_insert_range<internal::buffer<char_type>> range;
return this->vformat_to(range(buf), make_args_checked(format_, args...)); return this->vformat_to(range(buf), make_args_checked(format_, args...));
} }

View File

@ -180,7 +180,7 @@ class printf_width_handler : public function<unsigned> {
}; };
template <typename Char, typename Context> template <typename Char, typename Context>
void printf(basic_buffer<Char>& buf, basic_string_view<Char> format, void printf(buffer<Char>& buf, basic_string_view<Char> format,
basic_format_args<Context> args) { basic_format_args<Context> args) {
Context(std::back_inserter(buf), format, args).format(); Context(std::back_inserter(buf), format, args).format();
} }
@ -198,8 +198,8 @@ using internal::printf; // For printing into memory_buffer.
template <typename Range> class printf_arg_formatter; template <typename Range> class printf_arg_formatter;
template <typename OutputIt, typename Char, template <typename OutputIt, typename Char,
typename ArgFormatter = printf_arg_formatter< typename ArgFormatter =
back_insert_range<internal::basic_buffer<Char>>>> printf_arg_formatter<back_insert_range<internal::buffer<Char>>>>
class basic_printf_context; class basic_printf_context;
/** /**
@ -578,8 +578,8 @@ template <typename Buffer> struct basic_printf_context_t {
type; type;
}; };
typedef basic_printf_context_t<internal::buffer>::type printf_context; typedef basic_printf_context_t<internal::buffer<char>>::type printf_context;
typedef basic_printf_context_t<internal::wbuffer>::type wprintf_context; typedef basic_printf_context_t<internal::buffer<wchar_t>>::type wprintf_context;
typedef basic_format_args<printf_context> printf_args; typedef basic_format_args<printf_context> printf_args;
typedef basic_format_args<wprintf_context> wprintf_args; typedef basic_format_args<wprintf_context> wprintf_args;
@ -612,7 +612,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline std::basic_string<Char> vsprintf( inline std::basic_string<Char> vsprintf(
const S& format, const S& format,
basic_format_args< basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type> typename basic_printf_context_t<internal::buffer<Char>>::type>
args) { args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); printf(buffer, to_string_view(format), args);
@ -633,7 +633,7 @@ template <typename S, typename... Args,
inline std::basic_string<FMT_CHAR(S)> sprintf(const S& format, inline std::basic_string<FMT_CHAR(S)> sprintf(const S& format,
const Args&... args) { const Args&... args) {
internal::check_format_string<Args...>(format); internal::check_format_string<Args...>(format);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::buffer<FMT_CHAR(S)> buffer;
typedef typename basic_printf_context_t<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{args...}; format_arg_store<context, Args...> as{args...};
return vsprintf(to_string_view(format), basic_format_args<context>(as)); return vsprintf(to_string_view(format), basic_format_args<context>(as));
@ -643,7 +643,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline int vfprintf( inline int vfprintf(
std::FILE* f, const S& format, std::FILE* f, const S& format,
basic_format_args< basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type> typename basic_printf_context_t<internal::buffer<Char>>::type>
args) { args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); printf(buffer, to_string_view(format), args);
@ -666,7 +666,7 @@ template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)> FMT_ENABLE_IF(internal::is_string<S>::value)>
inline int fprintf(std::FILE* f, const S& format, const Args&... args) { inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
internal::check_format_string<Args...>(format); internal::check_format_string<Args...>(format);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::buffer<FMT_CHAR(S)> buffer;
typedef typename basic_printf_context_t<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{args...}; format_arg_store<context, Args...> as{args...};
return vfprintf(f, to_string_view(format), basic_format_args<context>(as)); return vfprintf(f, to_string_view(format), basic_format_args<context>(as));
@ -676,7 +676,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline int vprintf( inline int vprintf(
const S& format, const S& format,
basic_format_args< basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type> typename basic_printf_context_t<internal::buffer<Char>>::type>
args) { args) {
return vfprintf(stdout, to_string_view(format), args); return vfprintf(stdout, to_string_view(format), args);
} }
@ -694,7 +694,7 @@ template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)> FMT_ENABLE_IF(internal::is_string<S>::value)>
inline int printf(const S& format_str, const Args&... args) { inline int printf(const S& format_str, const Args&... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::buffer<FMT_CHAR(S)> buffer;
typedef typename basic_printf_context_t<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{args...}; format_arg_store<context, Args...> as{args...};
return vprintf(to_string_view(format_str), basic_format_args<context>(as)); return vprintf(to_string_view(format_str), basic_format_args<context>(as));
@ -704,7 +704,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline int vfprintf( inline int vfprintf(
std::basic_ostream<Char>& os, const S& format, std::basic_ostream<Char>& os, const S& format,
basic_format_args< basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type> typename basic_printf_context_t<internal::buffer<Char>>::type>
args) { args) {
basic_memory_buffer<Char> buffer; basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args); printf(buffer, to_string_view(format), args);
@ -726,7 +726,7 @@ template <typename S, typename... Args,
inline int fprintf(std::basic_ostream<FMT_CHAR(S)>& os, const S& format_str, inline int fprintf(std::basic_ostream<FMT_CHAR(S)>& os, const S& format_str,
const Args&... args) { const Args&... args) {
internal::check_format_string<Args...>(format_str); internal::check_format_string<Args...>(format_str);
typedef internal::basic_buffer<FMT_CHAR(S)> buffer; typedef internal::buffer<FMT_CHAR(S)> buffer;
typedef typename basic_printf_context_t<buffer>::type context; typedef typename basic_printf_context_t<buffer>::type context;
format_arg_store<context, Args...> as{args...}; format_arg_store<context, Args...> as{args...};
return vfprintf(os, to_string_view(format_str), return vfprintf(os, to_string_view(format_str),

View File

@ -41,10 +41,10 @@ namespace std {
template<class O, class charT> FMT_REQUIRES(OutputIterator<O, const charT&>) template<class O, class charT> FMT_REQUIRES(OutputIterator<O, const charT&>)
class basic_format_context; class basic_format_context;
using format_context = basic_format_context< using format_context = basic_format_context<
/* unspecified */ std::back_insert_iterator<fmt::internal::basic_buffer<char>>, /* unspecified */ std::back_insert_iterator<fmt::internal::buffer<char>>,
char>; char>;
using wformat_context = basic_format_context< using wformat_context = basic_format_context<
/* unspecified */ std::back_insert_iterator<fmt::internal::basic_buffer<wchar_t>>, /* unspecified */ std::back_insert_iterator<fmt::internal::buffer<wchar_t>>,
wchar_t>; wchar_t>;
template<class T, class charT = char> struct formatter { template<class T, class charT = char> struct formatter {
@ -686,8 +686,8 @@ template<class... Args>
string vformat(string_view fmt, format_args args) { string vformat(string_view fmt, format_args args) {
fmt::memory_buffer mbuf; fmt::memory_buffer mbuf;
fmt::internal::buffer& buf = mbuf; fmt::internal::buffer<char>& buf = mbuf;
typedef fmt::back_insert_range<fmt::internal::buffer> range; typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
detail::format_handler<detail::arg_formatter<range>, char, format_context> detail::format_handler<detail::arg_formatter<range>, char, format_context>
h(range(std::back_inserter(buf)), fmt, args, {}); h(range(std::back_inserter(buf)), fmt, args, {});
fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h); fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h);

View File

@ -11,7 +11,7 @@ FMT_BEGIN_NAMESPACE
template struct internal::basic_data<void>; template struct internal::basic_data<void>;
// Workaround a bug in MSVC2013 that prevents instantiation of grisu2_format. // Workaround a bug in MSVC2013 that prevents instantiation of grisu2_format.
bool (*instantiate_grisu2_format)(double, internal::buffer&, int, bool, bool (*instantiate_grisu2_format)(double, internal::buffer<char>&, int, bool,
int&) = internal::grisu2_format; int&) = internal::grisu2_format;
#ifndef FMT_STATIC_THOUSANDS_SEPARATOR #ifndef FMT_STATIC_THOUSANDS_SEPARATOR
@ -23,8 +23,7 @@ template FMT_API std::locale internal::locale_ref::get<std::locale>() const;
template FMT_API char internal::thousands_sep_impl(locale_ref); template FMT_API char internal::thousands_sep_impl(locale_ref);
template FMT_API void internal::basic_buffer<char>::append(const char*, template FMT_API void internal::buffer<char>::append(const char*, const char*);
const char*);
template FMT_API void internal::arg_map<format_context>::init( template FMT_API void internal::arg_map<format_context>::init(
const basic_format_args<format_context>& args); const basic_format_args<format_context>& args);
@ -43,19 +42,20 @@ template FMT_API std::string internal::vformat<char>(
string_view, basic_format_args<format_context>); string_view, basic_format_args<format_context>);
template FMT_API format_context::iterator internal::vformat_to( template FMT_API format_context::iterator internal::vformat_to(
internal::buffer&, string_view, basic_format_args<format_context>); internal::buffer<char>&, string_view, basic_format_args<format_context>);
template FMT_API void internal::sprintf_format(double, internal::buffer&, template FMT_API void internal::sprintf_format(double, internal::buffer<char>&,
core_format_specs); core_format_specs);
template FMT_API void internal::sprintf_format(long double, internal::buffer&, template FMT_API void internal::sprintf_format(long double,
internal::buffer<char>&,
core_format_specs); core_format_specs);
// Explicit instantiations for wchar_t. // Explicit instantiations for wchar_t.
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref); template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
template FMT_API void internal::basic_buffer<wchar_t>::append(const wchar_t*, template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
const wchar_t*); const wchar_t*);
template FMT_API void internal::arg_map<wformat_context>::init( template FMT_API void internal::arg_map<wformat_context>::init(
const basic_format_args<wformat_context>&); const basic_format_args<wformat_context>&);

View File

@ -31,7 +31,7 @@
using fmt::basic_format_arg; using fmt::basic_format_arg;
using fmt::string_view; using fmt::string_view;
using fmt::internal::basic_buffer; using fmt::internal::buffer;
using fmt::internal::value; using fmt::internal::value;
using testing::_; using testing::_;
@ -54,7 +54,7 @@ template <typename Char> struct formatter<test_struct, Char> {
return ctx.begin(); return ctx.begin();
} }
typedef std::back_insert_iterator<basic_buffer<Char>> iterator; typedef std::back_insert_iterator<buffer<Char>> iterator;
auto format(test_struct, basic_format_context<iterator, char>& ctx) auto format(test_struct, basic_format_context<iterator, char>& ctx)
-> decltype(ctx.out()) { -> decltype(ctx.out()) {
@ -66,28 +66,28 @@ FMT_END_NAMESPACE
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470 #if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470
TEST(BufferTest, Noncopyable) { TEST(BufferTest, Noncopyable) {
EXPECT_FALSE(std::is_copy_constructible<basic_buffer<char>>::value); EXPECT_FALSE(std::is_copy_constructible<buffer<char>>::value);
# if !FMT_MSC_VER # if !FMT_MSC_VER
// std::is_copy_assignable is broken in MSVC2013. // std::is_copy_assignable is broken in MSVC2013.
EXPECT_FALSE(std::is_copy_assignable<basic_buffer<char>>::value); EXPECT_FALSE(std::is_copy_assignable<buffer<char>>::value);
# endif # endif
} }
TEST(BufferTest, Nonmoveable) { TEST(BufferTest, Nonmoveable) {
EXPECT_FALSE(std::is_move_constructible<basic_buffer<char>>::value); EXPECT_FALSE(std::is_move_constructible<buffer<char>>::value);
# if !FMT_MSC_VER # if !FMT_MSC_VER
// std::is_move_assignable is broken in MSVC2013. // std::is_move_assignable is broken in MSVC2013.
EXPECT_FALSE(std::is_move_assignable<basic_buffer<char>>::value); EXPECT_FALSE(std::is_move_assignable<buffer<char>>::value);
# endif # endif
} }
#endif #endif
// A test buffer with a dummy grow method. // A test buffer with a dummy grow method.
template <typename T> struct test_buffer : basic_buffer<T> { template <typename T> struct test_buffer : buffer<T> {
void grow(std::size_t capacity) { this->set(FMT_NULL, capacity); } void grow(std::size_t capacity) { this->set(FMT_NULL, capacity); }
}; };
template <typename T> struct mock_buffer : basic_buffer<T> { template <typename T> struct mock_buffer : buffer<T> {
MOCK_METHOD1(do_grow, void(std::size_t capacity)); MOCK_METHOD1(do_grow, void(std::size_t capacity));
void grow(std::size_t capacity) { void grow(std::size_t capacity) {
@ -133,7 +133,7 @@ TEST(BufferTest, VirtualDtor) {
typedef StrictMock<dying_buffer> stict_mock_buffer; typedef StrictMock<dying_buffer> stict_mock_buffer;
stict_mock_buffer* mock_buffer = new stict_mock_buffer(); stict_mock_buffer* mock_buffer = new stict_mock_buffer();
EXPECT_CALL(*mock_buffer, die()); EXPECT_CALL(*mock_buffer, die());
basic_buffer<int>* buffer = mock_buffer; buffer<int>* buffer = mock_buffer;
delete buffer; delete buffer;
} }
@ -144,7 +144,7 @@ TEST(BufferTest, Access) {
EXPECT_EQ(11, buffer[0]); EXPECT_EQ(11, buffer[0]);
buffer[3] = 42; buffer[3] = 42;
EXPECT_EQ(42, *(&buffer[0] + 3)); EXPECT_EQ(42, *(&buffer[0] + 3));
const basic_buffer<char>& const_buffer = buffer; const fmt::internal::buffer<char>& const_buffer = buffer;
EXPECT_EQ(42, const_buffer[3]); EXPECT_EQ(42, const_buffer[3]);
} }
@ -293,7 +293,7 @@ VISIT_TYPE(float, double);
{ \ { \
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \ testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
EXPECT_CALL(visitor, visit(expected)); \ EXPECT_CALL(visitor, visit(expected)); \
typedef std::back_insert_iterator<basic_buffer<Char>> iterator; \ typedef std::back_insert_iterator<buffer<Char>> iterator; \
fmt::visit_format_arg( \ fmt::visit_format_arg( \
visitor, make_arg<fmt::basic_format_context<iterator, Char>>(value)); \ visitor, make_arg<fmt::basic_format_context<iterator, Char>>(value)); \
} }
@ -371,12 +371,12 @@ TEST(ArgTest, PointerArg) {
struct check_custom { struct check_custom {
test_result operator()( test_result operator()(
fmt::basic_format_arg<fmt::format_context>::handle h) const { fmt::basic_format_arg<fmt::format_context>::handle h) const {
struct test_buffer : fmt::internal::basic_buffer<char> { struct test_buffer : fmt::internal::buffer<char> {
char data[10]; char data[10];
test_buffer() : fmt::internal::basic_buffer<char>(data, 0, 10) {} test_buffer() : fmt::internal::buffer<char>(data, 0, 10) {}
void grow(std::size_t) {} void grow(std::size_t) {}
} buffer; } buffer;
fmt::internal::basic_buffer<char>& base = buffer; fmt::internal::buffer<char>& base = buffer;
fmt::format_parse_context parse_ctx(""); fmt::format_parse_context parse_ctx("");
fmt::format_context ctx(std::back_inserter(base), fmt::format_args()); fmt::format_context ctx(std::back_inserter(base), fmt::format_args());
h.format(parse_ctx, ctx); h.format(parse_ctx, ctx);

View File

@ -14,9 +14,10 @@
// A custom argument formatter that doesn't print `-` for floating-point values // A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0. // rounded to 0.
class custom_arg_formatter class custom_arg_formatter
: public fmt::arg_formatter<fmt::back_insert_range<fmt::internal::buffer>> { : public fmt::arg_formatter<
fmt::back_insert_range<fmt::internal::buffer<char>>> {
public: public:
typedef fmt::back_insert_range<fmt::internal::buffer> range; typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
typedef fmt::arg_formatter<range> base; typedef fmt::arg_formatter<range> base;
custom_arg_formatter(fmt::format_context& ctx, custom_arg_formatter(fmt::format_context& ctx,

View File

@ -20,8 +20,8 @@
# include <windows.h> # include <windows.h>
#endif #endif
#include "fmt/format.h"
#include "fmt/color.h" #include "fmt/color.h"
#include "fmt/format.h"
#include "gmock.h" #include "gmock.h"
#include "gtest-extra.h" #include "gtest-extra.h"
#include "mock-allocator.h" #include "mock-allocator.h"
@ -103,7 +103,7 @@ void std_format(long double value, std::wstring& result) {
template <typename Char, typename T> template <typename Char, typename T>
::testing::AssertionResult check_write(const T& value, const char* type) { ::testing::AssertionResult check_write(const T& value, const char* type) {
fmt::basic_memory_buffer<Char> buffer; fmt::basic_memory_buffer<Char> buffer;
typedef fmt::back_insert_range<fmt::internal::basic_buffer<Char>> range; typedef fmt::back_insert_range<fmt::internal::buffer<Char>> range;
fmt::basic_writer<range> writer(buffer); fmt::basic_writer<range> writer(buffer);
writer.write(value); writer.write(value);
std::basic_string<Char> actual = to_string(buffer); std::basic_string<Char> actual = to_string(buffer);
@ -472,8 +472,8 @@ TEST(UtilTest, UTF16ToUTF8Convert) {
} }
#endif // _WIN32 #endif // _WIN32
typedef void (*FormatErrorMessage)(fmt::internal::buffer& out, int error_code, typedef void (*FormatErrorMessage)(fmt::internal::buffer<char>& out,
string_view message); int error_code, string_view message);
template <typename Error> template <typename Error>
void check_throw_error(int error_code, FormatErrorMessage format) { void check_throw_error(int error_code, FormatErrorMessage format) {
@ -705,7 +705,8 @@ TEST(WriterTest, WriteUIntPtr) {
memory_buffer buf; memory_buffer buf;
fmt::writer writer(buf); fmt::writer writer(buf);
writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>( writer.write_pointer(fmt::internal::bit_cast<fmt::internal::uintptr_t>(
reinterpret_cast<void*>(0xface)), FMT_NULL); reinterpret_cast<void*>(0xface)),
FMT_NULL);
EXPECT_EQ("0xface", to_string(buf)); EXPECT_EQ("0xface", to_string(buf));
} }
@ -1948,7 +1949,7 @@ enum TestFixedEnum : short { B };
TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); } TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); }
#endif #endif
typedef fmt::back_insert_range<fmt::internal::buffer> buffer_range; typedef fmt::back_insert_range<fmt::internal::buffer<char>> buffer_range;
class mock_arg_formatter class mock_arg_formatter
: public fmt::internal::function< : public fmt::internal::function<

View File

@ -51,7 +51,7 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ(L"0", fmt::format(L"{}", A)); EXPECT_EQ(L"0", fmt::format(L"{}", A));
} }
typedef fmt::back_insert_range<fmt::internal::buffer> range; typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
struct test_arg_formatter : fmt::arg_formatter<range> { struct test_arg_formatter : fmt::arg_formatter<range> {
fmt::format_parse_context parse_ctx; fmt::format_parse_context parse_ctx;
@ -61,7 +61,7 @@ struct test_arg_formatter : fmt::arg_formatter<range> {
TEST(OStreamTest, CustomArg) { TEST(OStreamTest, CustomArg) {
fmt::memory_buffer buffer; fmt::memory_buffer buffer;
fmt::internal::buffer& base = buffer; fmt::internal::buffer<char>& base = buffer;
fmt::format_context ctx(std::back_inserter(base), fmt::format_args()); fmt::format_context ctx(std::back_inserter(base), fmt::format_args());
fmt::format_specs spec; fmt::format_specs spec;
test_arg_formatter af(ctx, spec); test_arg_formatter af(ctx, spec);
@ -134,7 +134,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
std::streamsize max_streamsize = std::numeric_limits<std::streamsize>::max(); std::streamsize max_streamsize = std::numeric_limits<std::streamsize>::max();
if (max_size <= fmt::internal::to_unsigned(max_streamsize)) return; if (max_size <= fmt::internal::to_unsigned(max_streamsize)) return;
struct test_buffer : fmt::internal::buffer { struct test_buffer : fmt::internal::buffer<char> {
explicit test_buffer(std::size_t size) { resize(size); } explicit test_buffer(std::size_t size) { resize(size); }
void grow(std::size_t) {} void grow(std::size_t) {}
} buffer(max_size); } buffer(max_size);

View File

@ -44,8 +44,8 @@ TEST(RangesTest, FormatPair) {
} }
TEST(RangesTest, FormatTuple) { TEST(RangesTest, FormatTuple) {
std::tuple<int64_t, float, std::string, char> tu1{42, 1.5f, std::tuple<int64_t, float, std::string, char> tu1{42, 1.5f, "this is tuple",
"this is tuple", 'i'}; 'i'};
EXPECT_EQ("(42, 1.5, \"this is tuple\", 'i')", fmt::format("{}", tu1)); EXPECT_EQ("(42, 1.5, \"this is tuple\", 'i')", fmt::format("{}", tu1));
} }