Remove buffer_appender

This commit is contained in:
Victor Zverovich 2024-01-07 22:03:02 -08:00
parent 679af1f5cc
commit 23e8109d8d
5 changed files with 24 additions and 28 deletions

View File

@ -1160,8 +1160,6 @@ constexpr auto has_const_formatter() -> bool {
return has_const_formatter_impl<Context>(static_cast<T*>(nullptr));
}
template <typename T> using buffer_appender = basic_appender<T>;
// Maps an output iterator to a buffer.
template <typename T, typename OutputIt>
auto get_buffer(OutputIt out) -> iterator_buffer<OutputIt, T> {
@ -1787,8 +1785,7 @@ template <typename OutputIt, typename Char> class basic_format_context {
};
template <typename Char>
using buffer_context =
basic_format_context<detail::buffer_appender<Char>, Char>;
using buffer_context = basic_format_context<basic_appender<Char>, Char>;
using format_context = basic_format_context<appender, char>;
template <typename T, typename Char = char>

View File

@ -52,7 +52,7 @@ FMT_FUNC void format_error_code(detail::buffer<char>& out, int error_code,
++error_code_size;
}
error_code_size += detail::to_unsigned(detail::count_digits(abs_value));
auto it = buffer_appender<char>(out);
auto it = appender(out);
if (message.size() <= inline_buffer_size - error_code_size)
fmt::format_to(it, FMT_STRING("{}{}"), message, SEP);
fmt::format_to(it, FMT_STRING("{}{}"), ERROR_STR, error_code);

View File

@ -582,7 +582,7 @@ reserve(std::back_insert_iterator<Container> it, size_t n) ->
}
template <typename T>
inline auto reserve(buffer_appender<T> it, size_t n) -> buffer_appender<T> {
inline auto reserve(basic_appender<T> it, size_t n) -> basic_appender<T> {
buffer<T>& buf = get_container(it);
buf.try_reserve(buf.size() + n);
return it;
@ -601,7 +601,7 @@ template <typename T, typename OutputIt>
constexpr auto to_pointer(OutputIt, size_t) -> T* {
return nullptr;
}
template <typename T> auto to_pointer(buffer_appender<T> it, size_t n) -> T* {
template <typename T> auto to_pointer(basic_appender<T> it, size_t n) -> T* {
buffer<T>& buf = get_container(it);
auto size = buf.size();
if (buf.capacity() < size + n) return nullptr;
@ -2190,7 +2190,7 @@ FMT_CONSTEXPR auto make_write_int_arg(T value, sign_t sign)
}
template <typename Char = char> struct loc_writer {
buffer_appender<Char> out;
basic_appender<Char> out;
const format_specs<Char>& specs;
std::basic_string<Char> sep;
std::string grouping;
@ -2275,7 +2275,7 @@ FMT_CONSTEXPR FMT_NOINLINE auto write_int_noinline(
template <typename Char, typename OutputIt, typename T,
FMT_ENABLE_IF(is_integral<T>::value &&
!std::is_same<T, bool>::value &&
std::is_same<OutputIt, buffer_appender<Char>>::value)>
std::is_same<OutputIt, basic_appender<Char>>::value)>
FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
const format_specs<Char>& specs,
locale_ref loc) -> OutputIt {
@ -2287,7 +2287,7 @@ FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
template <typename Char, typename OutputIt, typename T,
FMT_ENABLE_IF(is_integral<T>::value &&
!std::is_same<T, bool>::value &&
!std::is_same<OutputIt, buffer_appender<Char>>::value)>
!std::is_same<OutputIt, basic_appender<Char>>::value)>
FMT_CONSTEXPR FMT_INLINE auto write(OutputIt out, T value,
const format_specs<Char>& specs,
locale_ref loc) -> OutputIt {
@ -2614,8 +2614,8 @@ FMT_CONSTEXPR20 auto write_significand(OutputIt out, T significand,
decimal_point);
}
auto buffer = basic_memory_buffer<Char>();
write_significand(buffer_appender<Char>(buffer), significand,
significand_size, integral_size, decimal_point);
write_significand(basic_appender<Char>(buffer), significand, significand_size,
integral_size, decimal_point);
grouping.apply(
out, basic_string_view<Char>(buffer.data(), to_unsigned(integral_size)));
return detail::copy_str_noinline<Char>(buffer.data() + integral_size,
@ -3337,11 +3337,11 @@ FMT_CONSTEXPR20 auto format_float(Float value, int precision, float_specs specs,
// Use Dragonbox for the shortest format.
if (specs.binary32) {
auto dec = dragonbox::to_decimal(static_cast<float>(value));
write<char>(buffer_appender<char>(buf), dec.significand);
write<char>(appender(buf), dec.significand);
return dec.exponent;
}
auto dec = dragonbox::to_decimal(static_cast<double>(value));
write<char>(buffer_appender<char>(buf), dec.significand);
write<char>(appender(buf), dec.significand);
return dec.exponent;
} else {
// Extract significand bits and exponent bits.
@ -3789,7 +3789,7 @@ FMT_CONSTEXPR auto write(OutputIt out, const T& value)
// An argument visitor that formats the argument and writes it via the output
// iterator. It's a class and not a generic lambda for compatibility with C++11.
template <typename Char> struct default_arg_formatter {
using iterator = buffer_appender<Char>;
using iterator = basic_appender<Char>;
using context = buffer_context<Char>;
iterator out;
@ -3808,7 +3808,7 @@ template <typename Char> struct default_arg_formatter {
};
template <typename Char> struct arg_formatter {
using iterator = buffer_appender<Char>;
using iterator = basic_appender<Char>;
using context = buffer_context<Char>;
iterator out;
@ -4299,7 +4299,7 @@ namespace detail {
template <typename Char>
void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
typename vformat_args<Char>::type args, locale_ref loc) {
auto out = buffer_appender<Char>(buf);
auto out = basic_appender<Char>(buf);
if (fmt.size() == 2 && equal2(fmt.data(), "{}")) {
auto arg = args.get(0);
if (!arg) throw_format_error("argument not found");
@ -4311,7 +4311,7 @@ void vformat_to(buffer<Char>& buf, basic_string_view<Char> fmt,
basic_format_parse_context<Char> parse_context;
buffer_context<Char> context;
format_handler(buffer_appender<Char> p_out, basic_string_view<Char> str,
format_handler(basic_appender<Char> p_out, basic_string_view<Char> str,
basic_format_args<buffer_context<Char>> p_args,
locale_ref p_loc)
: parse_context(str), context(p_out, p_args, p_loc) {}

View File

@ -22,7 +22,7 @@ template <typename T> struct printf_formatter {
template <typename Char> class basic_printf_context {
private:
detail::buffer_appender<Char> out_;
basic_appender<Char> out_;
basic_format_args<basic_printf_context> args_;
static_assert(std::is_same<Char, char>::value ||
@ -40,12 +40,12 @@ template <typename Char> class basic_printf_context {
stored in the context object so make sure they have appropriate lifetimes.
\endrst
*/
basic_printf_context(detail::buffer_appender<Char> out,
basic_printf_context(basic_appender<Char> out,
basic_format_args<basic_printf_context> args)
: out_(out), args_(args) {}
auto out() -> detail::buffer_appender<Char> { return out_; }
void advance_to(detail::buffer_appender<Char>) {}
auto out() -> basic_appender<Char> { return out_; }
void advance_to(basic_appender<Char>) {}
auto locale() -> detail::locale_ref { return {}; }
@ -222,7 +222,7 @@ template <typename Char> class printf_width_handler {
// Workaround for a bug with the XL compiler when initializing
// printf_arg_formatter's base class.
template <typename Char>
auto make_arg_formatter(buffer_appender<Char> iter, format_specs<Char>& s)
auto make_arg_formatter(basic_appender<Char> iter, format_specs<Char>& s)
-> arg_formatter<Char> {
return {iter, s, locale_ref()};
}
@ -243,7 +243,7 @@ class printf_arg_formatter : public arg_formatter<Char> {
}
public:
printf_arg_formatter(buffer_appender<Char> iter, format_specs<Char>& s,
printf_arg_formatter(basic_appender<Char> iter, format_specs<Char>& s,
context_type& ctx)
: base(make_arg_formatter(iter, s)), context_(ctx) {}
@ -416,7 +416,7 @@ inline auto parse_printf_presentation_type(char c, type t)
template <typename Char, typename Context>
void vprintf(buffer<Char>& buf, basic_string_view<Char> format,
basic_format_args<Context> args) {
using iterator = buffer_appender<Char>;
using iterator = basic_appender<Char>;
auto out = iterator(buf);
auto context = basic_printf_context<Char>(out, args);
auto parse_ctx = basic_format_parse_context<Char>(format);

View File

@ -114,7 +114,7 @@ TEST(core_test, is_back_insert_iterator) {
TEST(core_test, buffer_appender) {
#ifdef __cpp_lib_ranges
static_assert(std::output_iterator<fmt::detail::buffer_appender<char>, char>);
static_assert(std::output_iterator<fmt::appender, char>);
#endif
}
@ -449,8 +449,7 @@ struct check_custom {
10) {}
} buffer;
auto parse_ctx = fmt::format_parse_context("");
auto ctx = fmt::format_context(fmt::detail::buffer_appender<char>(buffer),
fmt::format_args());
auto ctx = fmt::format_context(fmt::appender(buffer), fmt::format_args());
h.format(parse_ctx, ctx);
EXPECT_EQ("test", std::string(buffer.data, buffer.size()));
return test_result();