From 3245145a411effe9adccecb5fb6d1b528ac7acf7 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sat, 30 May 2020 13:03:41 -0700 Subject: [PATCH] Remove undocumented buffer_range and output_range --- include/fmt/format.h | 28 ------------------------- include/fmt/printf.h | 18 +++++++--------- test/ostream-test.cc | 4 ++-- test/printf-test.cc | 49 -------------------------------------------- 4 files changed, 9 insertions(+), 90 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index eb9895e9..d9b58eaa 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -495,22 +495,6 @@ class truncating_iterator truncating_iterator& operator*() { return *this; } }; -// A range with the specified output iterator and value type. -template -class output_range { - private: - OutputIt it_; - - public: - using value_type = T; - using iterator = OutputIt; - struct sentinel {}; - - explicit output_range(OutputIt it) : it_(it) {} - OutputIt begin() const { return it_; } - sentinel end() const { return {}; } // Sentinel is not used yet. -}; - template inline size_t count_code_points(basic_string_view s) { return s.size(); @@ -587,18 +571,6 @@ void buffer::append(const U* begin, const U* end) { } } // namespace detail -// DEPRECATED! A range with an iterator appending to a buffer. -template -class buffer_range - : public detail::output_range>, - T> { - public: - using iterator = std::back_insert_iterator>; - using detail::output_range::output_range; - buffer_range(detail::buffer& buf) - : detail::output_range(std::back_inserter(buf)) {} -}; - // The number of characters to store in the basic_memory_buffer object itself // to avoid dynamic memory allocation. enum { inline_buffer_size = 500 }; diff --git a/include/fmt/printf.h b/include/fmt/printf.h index 0649abb3..3a16890f 100644 --- a/include/fmt/printf.h +++ b/include/fmt/printf.h @@ -194,8 +194,6 @@ FMT_DEPRECATED void printf(detail::buffer& buf, } using detail::vprintf; -template class printf_arg_formatter; - template class basic_printf_parse_context : public basic_format_parse_context { using basic_format_parse_context::basic_format_parse_context; @@ -207,18 +205,16 @@ template class basic_printf_context; The ``printf`` argument formatter. \endrst */ -template +template class printf_arg_formatter - : public detail::arg_formatter_base { + : public detail::arg_formatter_base { public: - using iterator = typename Range::iterator; + using iterator = OutputIt; private: - using char_type = typename Range::value_type; - using base = detail::arg_formatter_base; - using context_type = basic_printf_context; + using char_type = Char; + using base = detail::arg_formatter_base; + using context_type = basic_printf_context; context_type& context_; @@ -389,7 +385,7 @@ template class basic_printf_context { } /** Formats stored arguments and writes the output to the range. */ - template >> + template > OutputIt format(); }; diff --git a/test/ostream-test.cc b/test/ostream-test.cc index d9dfb6c6..c4e8a27f 100644 --- a/test/ostream-test.cc +++ b/test/ostream-test.cc @@ -65,10 +65,10 @@ TEST(OStreamTest, Enum) { } struct test_arg_formatter - : fmt::arg_formatter::iterator, char> { + : fmt::arg_formatter { fmt::format_parse_context parse_ctx; test_arg_formatter(fmt::format_context& ctx, fmt::format_specs& s) - : fmt::arg_formatter::iterator, char>( + : fmt::arg_formatter( ctx, &parse_ctx, &s), parse_ctx("") {} }; diff --git a/test/printf-test.cc b/test/printf-test.cc index da980e80..1c1173c4 100644 --- a/test/printf-test.cc +++ b/test/printf-test.cc @@ -606,52 +606,3 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) { {fmt::make_wprintf_args(42, L"something")})); #endif } - -typedef fmt::printf_arg_formatter> formatter_t; -typedef fmt::basic_printf_context context_t; - -// A custom printf argument formatter that doesn't print `-` for floating-point -// values rounded to 0. -class custom_printf_arg_formatter : public formatter_t { - public: - using formatter_t::iterator; - - custom_printf_arg_formatter(formatter_t::iterator iter, - formatter_t::format_specs& specs, context_t& ctx) - : formatter_t(iter, specs, ctx) {} - - using formatter_t::operator(); - -#if FMT_MSC_VER > 0 && FMT_MSC_VER <= 1804 - template ::value)> - iterator operator()(T value){ -#else - iterator operator()(double value) { -#endif - // Comparing a float to 0.0 is safe. - if (round(value * pow(10, specs()->precision)) == 0.0) value = 0; - return formatter_t::operator()(value); -} -} -; - -typedef fmt::basic_format_args format_args_t; - -std::string custom_vformat(fmt::string_view format_str, format_args_t args) { - fmt::memory_buffer buffer; - fmt::vprintf(buffer, format_str, args); - return std::string(buffer.data(), buffer.size()); -} - -template -std::string custom_format(const char* format_str, const Args&... args) { - auto va = fmt::make_printf_args(args...); - return custom_vformat(format_str, {va}); -} - -TEST(PrintfTest, CustomFormat) { - EXPECT_EQ("0.00", custom_format("%.2f", -.00001)); - EXPECT_EQ("0.00", custom_format("%.2f", .00001)); - EXPECT_EQ("1.00", custom_format("%.2f", 1.00001)); - EXPECT_EQ("-1.00", custom_format("%.2f", -1.00001)); -}