diff --git a/include/fmt/core.h b/include/fmt/core.h index d7d2de50..1def5d6f 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -1841,6 +1841,14 @@ inline auto format_to_n(OutputIt out, size_t n, const S& format_str, Returns the number of characters in the output of ``format(format_str, args...)``. */ +template ::value)> +inline size_t formatted_size(const S& format_str, Args&&... args) { + const auto& vargs = fmt::make_args_checked(format_str, args...); + detail::counting_buffer<> buf; + detail::vformat_to(buf, to_string_view(format_str), vargs); + return buf.count(); +} + template inline size_t formatted_size(string_view format_str, Args&&... args) { const auto& vargs = fmt::make_args_checked(format_str, args...); diff --git a/test/enforce-compiletime-test.cc b/test/enforce-compiletime-test.cc index 79ab3e82..0260187e 100644 --- a/test/enforce-compiletime-test.cc +++ b/test/enforce-compiletime-test.cc @@ -157,7 +157,7 @@ TEST(FormatTest, OutputIterators) { } TEST(FormatTest, FormattedSize) { - //EXPECT_EQ(2u, fmt::formatted_size(FMT_STRING("{}"), 42)); + EXPECT_EQ(2u, fmt::formatted_size(FMT_STRING("{}"), 42)); } TEST(FormatTest, FormatTo) {