From 3176e0fad7e99904d33d1cd0d04da11479066927 Mon Sep 17 00:00:00 2001 From: gerboengels Date: Wed, 7 Sep 2022 23:15:12 +0200 Subject: [PATCH] Add locale overload for formatted_size (#3084) (#3087) Co-authored-by: Gerbo Engels --- include/fmt/format.h | 12 ++++++++++++ test/format-test.cc | 1 + 2 files changed, 13 insertions(+) diff --git a/include/fmt/format.h b/include/fmt/format.h index 43dc215a..3734b419 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -4270,6 +4270,18 @@ FMT_INLINE auto format_to(OutputIt out, const Locale& loc, return vformat_to(out, loc, fmt, fmt::make_format_args(args...)); } +template ::value)> +FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc, + format_string fmt, + T&&... args) -> size_t { + auto buf = detail::counting_buffer<>(); + detail::vformat_to(buf, string_view(fmt), + format_args(fmt::make_format_args(args...)), + detail::locale_ref(loc)); + return buf.count(); +} + FMT_MODULE_EXPORT_END FMT_END_NAMESPACE diff --git a/test/format-test.cc b/test/format-test.cc index ee722ab3..862a3cb3 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -2006,6 +2006,7 @@ TEST(format_test, output_iterators) { TEST(format_test, formatted_size) { EXPECT_EQ(2u, fmt::formatted_size("{}", 42)); + EXPECT_EQ(2u, fmt::formatted_size(std::locale(), "{}", 42)); } TEST(format_test, format_to_no_args) {