Skip to content

Commit

Permalink
Add locale overload for formatted_size (#3084) (#3087)
Browse files Browse the repository at this point in the history
Co-authored-by: Gerbo Engels <[email protected]>
  • Loading branch information
gerboengels and gerbo-work authored Sep 7, 2022
1 parent 1feb430 commit 3176e0f
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
12 changes: 12 additions & 0 deletions include/fmt/format.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename Locale, typename... T,
FMT_ENABLE_IF(detail::is_locale<Locale>::value)>
FMT_NODISCARD FMT_INLINE auto formatted_size(const Locale& loc,
format_string<T...> 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

Expand Down
1 change: 1 addition & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down

0 comments on commit 3176e0f

Please sign in to comment.