fix typo which caused the loss of the counting information when using a printf context with a truncating_iterator

This commit is contained in:
rimathia 2020-06-05 15:09:14 +02:00 committed by Victor Zverovich
parent 21409cfdda
commit 95c6ac0cc8
2 changed files with 22 additions and 3 deletions

View File

@ -206,8 +206,7 @@ template <typename OutputIt, typename Char> class basic_printf_context;
\endrst \endrst
*/ */
template <typename OutputIt, typename Char> template <typename OutputIt, typename Char>
class printf_arg_formatter class printf_arg_formatter : public detail::arg_formatter_base<OutputIt, Char> {
: public detail::arg_formatter_base<OutputIt, Char> {
public: public:
using iterator = OutputIt; using iterator = OutputIt;
@ -592,7 +591,7 @@ OutputIt basic_printf_context<OutputIt, Char>::format() {
start = it; start = it;
// Format argument. // Format argument.
visit_format_arg(ArgFormatter(out, specs, *this), arg); out = visit_format_arg(ArgFormatter(out, specs, *this), arg);
} }
return std::copy(start, it, out); return std::copy(start, it, out);
} }

View File

@ -606,3 +606,23 @@ TEST(PrintfTest, VSPrintfMakeWArgsExample) {
{fmt::make_wprintf_args(42, L"something")})); {fmt::make_wprintf_args(42, L"something")}));
#endif #endif
} }
TEST(PrintfTest, PrintfDetermineOutputSize) {
using backit = std::back_insert_iterator<std::vector<char>>;
using truncated_printf_context =
fmt::basic_printf_context<fmt::detail::truncating_iterator<backit>, char>;
auto v = std::vector<char>{};
auto it = std::back_inserter(v);
const auto format_string = "%s";
const auto format_arg = "Hello";
const auto expected_size = fmt::sprintf(format_string, format_arg).size();
EXPECT_EQ((truncated_printf_context(
fmt::detail::truncating_iterator<backit>(it, 0), format_string,
fmt::make_format_args<truncated_printf_context>(format_arg))
.format()
.count()),
expected_size);
}