back_insert_range<internal::buffer> -> buffer_range

This commit is contained in:
Victor Zverovich 2019-06-19 13:51:36 -07:00
parent 22ddd4b989
commit f13906f408
9 changed files with 39 additions and 39 deletions

View File

@ -191,10 +191,6 @@ FMT_END_NAMESPACE
FMT_BEGIN_NAMESPACE
namespace internal {
#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 1
#endif
// A fallback implementation of uintptr_t for systems that lack it.
struct fallback_uintptr {
unsigned char value[sizeof(void*)];
@ -205,11 +201,6 @@ using uintptr_t = ::uintptr_t;
using uintptr_t = fallback_uintptr;
#endif
template <typename T> inline bool use_grisu() {
return FMT_USE_GRISU && std::numeric_limits<double>::is_iec559 &&
sizeof(T) <= sizeof(double);
}
// An equivalent of `*reinterpret_cast<Dest*>(&source)` that doesn't produce
// undefined behavior (e.g. due to type aliasing).
// Example: uint64_t d = bit_cast<uint64_t>(2.718);
@ -224,6 +215,30 @@ inline Dest bit_cast(const Source& source) {
// An implementation of iterator_t for pre-C++20 systems.
template <typename T>
using iterator_t = decltype(std::begin(std::declval<T&>()));
#ifndef FMT_USE_GRISU
# define FMT_USE_GRISU 1
#endif
template <typename T> inline bool use_grisu() {
return FMT_USE_GRISU && std::numeric_limits<double>::is_iec559 &&
sizeof(T) <= sizeof(double);
}
// A range whose output iterator appends to a buffer.
template <typename T> class buffer_range {
public:
using value_type = T;
using iterator = std::back_insert_iterator<internal::buffer<T>>;
private:
iterator begin_;
public:
buffer_range(internal::buffer<T>& buf) : begin_(std::back_inserter(buf)) {}
explicit buffer_range(iterator it) : begin_(it) {}
iterator begin() const { return begin_; }
};
} // namespace internal
template <typename OutputIt, typename T = typename OutputIt::value_type>
@ -243,22 +258,9 @@ class output_range {
OutputIt begin() const { return it_; }
};
// A range where begin() returns back_insert_iterator.
template <typename Container>
class back_insert_range
: public output_range<std::back_insert_iterator<Container>> {
using base = output_range<std::back_insert_iterator<Container>>;
public:
using value_type = typename Container::value_type;
back_insert_range(Container& c) : base(std::back_inserter(c)) {}
back_insert_range(typename base::iterator it) : base(it) {}
};
template <typename Range> class basic_writer;
using writer = basic_writer<back_insert_range<internal::buffer<char>>>;
using wwriter = basic_writer<back_insert_range<internal::buffer<wchar_t>>>;
using writer = basic_writer<internal::buffer_range<char>>;
using wwriter = basic_writer<internal::buffer_range<wchar_t>>;
/** A formatting error such as invalid format string. */
class format_error : public std::runtime_error {
@ -3284,7 +3286,7 @@ template <typename Char>
typename buffer_context<Char>::iterator internal::vformat_to(
internal::buffer<Char>& buf, basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<internal::buffer<Char>> range;
using range = buffer_range<Char>;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str),
args);
}

View File

@ -19,7 +19,7 @@ typename buffer_context<Char>::iterator vformat_to(
const std::locale& loc, buffer<Char>& buf,
basic_string_view<Char> format_str,
basic_format_args<buffer_context<Char>> args) {
typedef back_insert_range<buffer<Char>> range;
using range = buffer_range<Char>;
return vformat_to<arg_formatter<range>>(buf, to_string_view(format_str), args,
internal::locale_ref(loc));
}

View File

@ -214,7 +214,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::buffer<char_type>> range;
using range = buffer_range<char_type>;
this->vformat_to(range(buffer), basic_format_args<context>{
make_args_checked(format_, args...)});
return to_string(buffer);
@ -224,7 +224,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::buffer<char_type>> range;
using range = buffer_range<char_type>;
this->vformat_to(range(buffer), basic_format_args<context>{
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>::iterator format_to(
basic_memory_buffer<char_type, SIZE>& buf, const Args&... args) const {
typedef back_insert_range<internal::buffer<char_type>> range;
using range = buffer_range<char_type>;
return this->vformat_to(
range(buf),
basic_format_args<context>{make_args_checked(format_, args...)});

View File

@ -368,7 +368,7 @@ template <typename OutputIt, typename Char> class basic_printf_context {
/** Formats stored arguments and writes the output to the range. */
template <typename ArgFormatter =
printf_arg_formatter<back_insert_range<internal::buffer<Char>>>>
printf_arg_formatter<internal::buffer_range<Char>>>
OutputIt format();
};

View File

@ -18,10 +18,9 @@
// 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<char>>> {
: public fmt::arg_formatter<fmt::internal::buffer_range<char>> {
public:
typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
using range = fmt::internal::buffer_range<char>;
typedef fmt::arg_formatter<range> base;
custom_arg_formatter(fmt::format_context& ctx,

View File

@ -719,7 +719,7 @@ template<class... Args>
string vformat(string_view fmt, format_args args) {
fmt::memory_buffer mbuf;
fmt::internal::buffer<char>& buf = mbuf;
typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
using range = fmt::internal::buffer_range<char>;
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);

View File

@ -99,7 +99,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::buffer<Char>> range;
using range = fmt::internal::buffer_range<Char>;
fmt::basic_writer<range> writer(buffer);
writer.write(value);
std::basic_string<Char> actual = to_string(buffer);
@ -1894,7 +1894,7 @@ enum TestFixedEnum : short { B };
TEST(FormatTest, FixedEnum) { EXPECT_EQ("0", fmt::format("{}", B)); }
#endif
typedef fmt::back_insert_range<fmt::internal::buffer<char>> buffer_range;
using buffer_range = fmt::internal::buffer_range<char>;
class mock_arg_formatter
: public fmt::internal::arg_formatter_base<buffer_range> {

View File

@ -64,7 +64,7 @@ TEST(OStreamTest, Enum) {
EXPECT_EQ(L"0", fmt::format(L"{}", unstreamable_enum()));
}
typedef fmt::back_insert_range<fmt::internal::buffer<char>> range;
using range = fmt::internal::buffer_range<char>;
struct test_arg_formatter : fmt::arg_formatter<range> {
fmt::format_parse_context parse_ctx;

View File

@ -561,8 +561,7 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
#endif
}
typedef fmt::printf_arg_formatter<
fmt::back_insert_range<fmt::internal::buffer<char>>>
typedef fmt::printf_arg_formatter<fmt::internal::buffer_range<char>>
formatter_t;
typedef fmt::basic_printf_context<formatter_t::iterator, char> context_t;