Commit 28083954 authored by Victor Zverovich's avatar Victor Zverovich

basic_buffer -> buffer

This reduces symbol sizes and gets rid of shadowing warnings.
parent 6e37c200
......@@ -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. */
template <typename T> class basic_buffer {
template <typename T> class buffer {
private:
basic_buffer(const basic_buffer&) = delete;
void operator=(const basic_buffer&) = delete;
buffer(const buffer&) = delete;
void operator=(const buffer&) = delete;
T* ptr_;
std::size_t size_;
......@@ -252,12 +252,12 @@ template <typename T> class basic_buffer {
protected:
// 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,
std::size_t cap = 0) FMT_NOEXCEPT : ptr_(p),
size_(sz),
capacity_(cap) {}
buffer(T* p = FMT_NULL, std::size_t sz = 0, std::size_t cap = 0) FMT_NOEXCEPT
: ptr_(p),
size_(sz),
capacity_(cap) {}
/** Sets the buffer data and capacity. */
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 const T& const_reference;
virtual ~basic_buffer() {}
virtual ~buffer() {}
T* begin() FMT_NOEXCEPT { return ptr_; }
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]; }
};
typedef basic_buffer<char> buffer;
typedef basic_buffer<wchar_t> wbuffer;
// A container-backed buffer.
template <typename Container>
class container_buffer : public basic_buffer<typename Container::value_type> {
class container_buffer : public buffer<typename Container::value_type> {
private:
Container& container_;
......@@ -334,7 +331,7 @@ class container_buffer : public basic_buffer<typename Container::value_type> {
public:
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.
......@@ -1141,7 +1138,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
template <typename Char> struct buffer_context {
typedef basic_format_context<
std::back_insert_iterator<internal::basic_buffer<Char>>, Char>
std::back_insert_iterator<internal::buffer<Char>>, Char>
type;
};
typedef buffer_context<char>::type format_context;
......@@ -1381,7 +1378,7 @@ std::basic_string<Char> vformat(
template <typename Char>
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);
} // namespace internal
......@@ -1415,7 +1412,7 @@ template <typename Char>
struct is_contiguous<std::basic_string<Char>> : std::true_type {};
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``. */
template <typename Container, typename S>
......
......@@ -85,7 +85,7 @@ inline int fmt_snprintf(char* buffer, size_t size, const char* format, ...) {
# define FMT_SWPRINTF swprintf
#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.
// 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();
}
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 {
// Report error code making sure that the output fits into
// inline_buffer_size to avoid dynamic memory allocation and potential
......@@ -661,7 +661,7 @@ struct shortest_handler {
template <typename Double, typename std::enable_if<
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) {
FMT_ASSERT(value >= 0, "value is negative");
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>
void sprintf_format(Double value, internal::buffer& buf,
void sprintf_format(Double value, internal::buffer<char>& buf,
core_format_specs spec) {
// Buffer capacity must be non-zero, otherwise MSVC's vsnprintf_s will fail.
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));
}
FMT_FUNC void internal::format_windows_error(internal::buffer& out,
FMT_FUNC void internal::format_windows_error(internal::buffer<char>& out,
int error_code,
string_view message) FMT_NOEXCEPT {
FMT_TRY {
......@@ -883,7 +883,7 @@ FMT_FUNC void internal::format_windows_error(internal::buffer& out,
#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 {
FMT_TRY {
memory_buffer buf;
......
......@@ -352,8 +352,8 @@ class back_insert_range
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::wbuffer>> wwriter;
typedef basic_writer<back_insert_range<internal::buffer<char>>> writer;
typedef basic_writer<back_insert_range<internal::buffer<wchar_t>>> wwriter;
/** A formatting error such as invalid format string. */
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 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);
reserve(new_size);
std::uninitialized_copy(begin, end,
......@@ -454,8 +454,7 @@ enum { inline_buffer_size = 500 };
*/
template <typename T, std::size_t SIZE = inline_buffer_size,
typename Allocator = std::allocator<T>>
class basic_memory_buffer : private Allocator,
public internal::basic_buffer<T> {
class basic_memory_buffer : private Allocator, public internal::buffer<T> {
private:
T store_[SIZE];
......@@ -1087,7 +1086,8 @@ class utf16_to_utf8 {
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;
#endif
......@@ -1149,10 +1149,10 @@ namespace internal {
// Formats value using Grisu2 algorithm:
// https://www.cs.tufts.edu/~nr/cs257/archive/florian-loitsch/printf.pdf
template <typename Double, FMT_ENABLE_IF(sizeof(Double) == sizeof(uint64_t))>
FMT_API bool grisu2_format(Double value, buffer& buf, int precision, bool fixed,
int& exp);
FMT_API bool grisu2_format(Double value, buffer<char>& buf, int precision,
bool fixed, int& exp);
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;
}
......@@ -1242,7 +1242,7 @@ It grisu2_prettify(const char* digits, int size, int exp, It it,
}
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>
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.
\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;
/**
......@@ -2654,7 +2654,7 @@ template <typename Range> class basic_writer {
struct double_writer {
char sign;
internal::buffer& buffer;
internal::buffer<char>& buffer;
size_t size() const { return buffer.size() + (sign ? 1 : 0); }
size_t width() const { return size(); }
......@@ -2667,14 +2667,14 @@ template <typename Range> class basic_writer {
class grisu_writer {
private:
internal::buffer& digits_;
internal::buffer<char>& digits_;
size_t size_;
char sign_;
int exp_;
internal::gen_digits_params params_;
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)
: digits_(digits), sign_(sign), exp_(exp), params_(params) {
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>
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) {
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),
args);
}
......@@ -3402,7 +3402,7 @@ typename buffer_context<Char>::type::iterator internal::vformat_to(
template <typename S, typename Char = FMT_CHAR(S),
FMT_ENABLE_IF(internal::is_string<S>::value)>
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) {
return internal::vformat_to(buf, to_string_view(format_str), args);
}
......
......@@ -16,10 +16,10 @@ FMT_BEGIN_NAMESPACE
namespace internal {
template <typename Char>
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_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,
internal::locale_ref(loc));
}
......
......@@ -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>::traits_type traits_type;
basic_buffer<Char>& buffer_;
buffer<Char>& buffer_;
public:
formatbuf(basic_buffer<Char>& buffer) : buffer_(buffer) {}
formatbuf(buffer<Char>& buffer) : buffer_(buffer) {}
protected:
// 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.
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();
typedef std::make_unsigned<std::streamsize>::type UnsignedStreamSize;
UnsignedStreamSize size = buf.size();
......@@ -86,7 +86,7 @@ void write(std::basic_ostream<Char>& os, basic_buffer<Char>& buf) {
}
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);
std::basic_ostream<Char> output(&format_buf);
output.exceptions(std::ios_base::failbit | std::ios_base::badbit);
......
......@@ -216,7 +216,7 @@ class prepared_format {
std::basic_string<char_type> format(const Args&... args) const {
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...));
return to_string(buffer);
}
......@@ -225,7 +225,7 @@ class prepared_format {
inline std::back_insert_iterator<Container> format_to(
std::back_insert_iterator<Container> out, const Args&... args) const {
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...));
return out;
}
......@@ -241,7 +241,7 @@ class prepared_format {
template <std::size_t SIZE = inline_buffer_size>
inline typename buffer_context<char_type>::type::iterator format_to(
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...));
}
......
......@@ -180,7 +180,7 @@ class printf_width_handler : public function<unsigned> {
};
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) {
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 OutputIt, typename Char,
typename ArgFormatter = printf_arg_formatter<
back_insert_range<internal::basic_buffer<Char>>>>
typename ArgFormatter =
printf_arg_formatter<back_insert_range<internal::buffer<Char>>>>
class basic_printf_context;
/**
......@@ -578,8 +578,8 @@ template <typename Buffer> struct basic_printf_context_t {
type;
};
typedef basic_printf_context_t<internal::buffer>::type printf_context;
typedef basic_printf_context_t<internal::wbuffer>::type wprintf_context;
typedef basic_printf_context_t<internal::buffer<char>>::type printf_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<wprintf_context> wprintf_args;
......@@ -612,7 +612,7 @@ template <typename S, typename Char = FMT_CHAR(S)>
inline std::basic_string<Char> vsprintf(
const S& format,
basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type>
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_memory_buffer<Char> buffer;
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,
const Args&... args) {
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;
format_arg_store<context, Args...> as{args...};
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(
std::FILE* f, const S& format,
basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type>
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_memory_buffer<Char> buffer;
printf(buffer, to_string_view(format), args);
......@@ -666,7 +666,7 @@ template <typename S, typename... Args,
FMT_ENABLE_IF(internal::is_string<S>::value)>
inline int fprintf(std::FILE* f, const S& format, const Args&... args) {
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;
format_arg_store<context, Args...> as{args...};
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(
const S& format,
basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type>
typename basic_printf_context_t<internal::buffer<Char>>::type>
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)>
inline int printf(const S& format_str, const Args&... args) {
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;
format_arg_store<context, Args...> as{args...};
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(
std::basic_ostream<Char>& os, const S& format,
basic_format_args<
typename basic_printf_context_t<internal::basic_buffer<Char>>::type>
typename basic_printf_context_t<internal::buffer<Char>>::type>
args) {
basic_memory_buffer<Char> buffer;
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,
const Args&... args) {
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;
format_arg_store<context, Args...> as{args...};
return vfprintf(os, to_string_view(format_str),
......
......@@ -41,10 +41,10 @@ namespace std {
template<class O, class charT> FMT_REQUIRES(OutputIterator<O, const charT&>)
class 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>;
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>;
template<class T, class charT = char> struct formatter {
......@@ -686,8 +686,8 @@ template<class... Args>
string vformat(string_view fmt, format_args args) {
fmt::memory_buffer mbuf;
fmt::internal::buffer& buf = mbuf;
typedef fmt::back_insert_range<fmt::internal::buffer> range;
fmt::internal::buffer<char>& buf = mbuf;
typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
detail::format_handler<detail::arg_formatter<range>, char, format_context>
h(range(std::back_inserter(buf)), fmt, args, {});
fmt::internal::parse_format_string<false>(fmt::to_string_view(fmt), h);
......
......@@ -11,7 +11,7 @@ FMT_BEGIN_NAMESPACE
template struct internal::basic_data<void>;
// 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;
#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 void internal::basic_buffer<char>::append(const char*,
const char*);
template FMT_API void internal::buffer<char>::append(const char*, const char*);
template FMT_API void internal::arg_map<format_context>::init(
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>);
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);
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);
// Explicit instantiations for wchar_t.
template FMT_API wchar_t internal::thousands_sep_impl(locale_ref);
template FMT_API void internal::basic_buffer<wchar_t>::append(const wchar_t*,
const wchar_t*);
template FMT_API void internal::buffer<wchar_t>::append(const wchar_t*,
const wchar_t*);
template FMT_API void internal::arg_map<wformat_context>::init(
const basic_format_args<wformat_context>&);
......
......@@ -31,7 +31,7 @@
using fmt::basic_format_arg;
using fmt::string_view;
using fmt::internal::basic_buffer;
using fmt::internal::buffer;
using fmt::internal::value;
using testing::_;
......@@ -54,7 +54,7 @@ template <typename Char> struct formatter<test_struct, Char> {
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)
-> decltype(ctx.out()) {
......@@ -66,28 +66,28 @@ FMT_END_NAMESPACE
#if !FMT_GCC_VERSION || FMT_GCC_VERSION >= 470
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
// 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
}
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
// 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
// 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); }
};
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));
void grow(std::size_t capacity) {
......@@ -133,7 +133,7 @@ TEST(BufferTest, VirtualDtor) {
typedef StrictMock<dying_buffer> stict_mock_buffer;
stict_mock_buffer* mock_buffer = new stict_mock_buffer();
EXPECT_CALL(*mock_buffer, die());
basic_buffer<int>* buffer = mock_buffer;
buffer<int>* buffer = mock_buffer;
delete buffer;
}
......@@ -144,7 +144,7 @@ TEST(BufferTest, Access) {
EXPECT_EQ(11, buffer[0]);
buffer[3] = 42;
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]);
}
......@@ -293,7 +293,7 @@ VISIT_TYPE(float, double);
{ \
testing::StrictMock<mock_visitor<decltype(expected)>> visitor; \
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( \
visitor, make_arg<fmt::basic_format_context<iterator, Char>>(value)); \
}
......@@ -371,12 +371,12 @@ TEST(ArgTest, PointerArg) {
struct check_custom {
test_result operator()(
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];
test_buffer() : fmt::internal::basic_buffer<char>(data, 0, 10) {}
test_buffer() : fmt::internal::buffer<char>(data, 0, 10) {}
void grow(std::size_t) {}
} buffer;
fmt::internal::basic_buffer<char>& base = buffer;
fmt::internal::buffer<char>& base = buffer;
fmt::format_parse_context parse_ctx("");
fmt::format_context ctx(std::back_inserter(base), fmt::format_args());
h.format(parse_ctx, ctx);
......
......@@ -14,9 +14,10 @@
// A custom argument formatter that doesn't print `-` for floating-point values
// rounded to 0.
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:
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;
custom_arg_formatter(fmt::format_context& ctx,
......
......@@ -20,8 +20,8 @@
# include <windows.h>
#endif
#include "fmt/format.h"
#include "fmt/color.h"
#include "fmt/format.h"
#include "gmock.h"
#include "gtest-extra.h"
#include "mock-allocator.h"
......@@ -103,7 +103,7 @@ void std_format(long double value, std::wstring& result) {
template <typename Char, typename T>
::testing::AssertionResult check_write(const T& value, const char* type) {
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);
writer.write(value);
std::basic_string<Char> actual = to_string(buffer);
......@@ -472,8 +472,8 @@ TEST(UtilTest, UTF16ToUTF8Convert) {
}
#endif // _WIN32
typedef void (*FormatErrorMessage)(fmt::internal::buffer& out, int error_code,
string_view message);
typedef void (*FormatErrorMessage)(fmt::internal::buffer<char>& out,
int error_code, string_view message);
template <typename Error>
void check_throw_error(int error_code, FormatErrorMessage format) {
......@@ -705,7 +705,8 @@ TEST(WriterTest, WriteUIntPtr) {
memory_buffer buf;
fmt::writer writer(buf);
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));
}
......@@ -1948,7 +1949,7 @@ enum TestFixedEnum : short { B };
TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); }
#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
: public fmt::internal::function<
......
......@@ -51,7 +51,7 @@ TEST(OStreamTest, Enum) {
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> {
fmt::format_parse_context parse_ctx;
......@@ -61,7 +61,7 @@ struct test_arg_formatter : fmt::arg_formatter<range> {
TEST(OStreamTest, CustomArg) {
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_specs spec;
test_arg_formatter af(ctx, spec);
......@@ -134,7 +134,7 @@ TEST(OStreamTest, WriteToOStreamMaxSize) {
std::streamsize max_streamsize = std::numeric_limits<std::streamsize>::max();
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); }
void grow(std::size_t) {}
} buffer(max_size);
......
......@@ -44,8 +44,8 @@ TEST(RangesTest, FormatPair) {
}
TEST(RangesTest, FormatTuple) {
std::tuple<int64_t, float, std::string, char> tu1{42, 1.5f,
"this is tuple", 'i'};
std::tuple<int64_t, float, std::string, char> tu1{42, 1.5f, "this is tuple",
'i'};
EXPECT_EQ("(42, 1.5, \"this is tuple\", 'i')", fmt::format("{}", tu1));
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment