thousands -> group_digits

This commit is contained in:
Victor Zverovich 2021-09-05 06:47:18 -07:00
parent c4d0f96a6d
commit 3940de5952
2 changed files with 8 additions and 8 deletions

View File

@ -2611,14 +2611,14 @@ template <> struct formatter<bytes> {
} }
}; };
// thousands_view is not derived from view because it copies the argument. // group_digits_view is not derived from view because it copies the argument.
template <typename T> struct thousands_view { T value; }; template <typename T> struct group_digits_view { T value; };
template <typename T> auto thousands(T value) -> thousands_view<T> { template <typename T> auto group_digits(T value) -> group_digits_view<T> {
return {value}; return {value};
} }
template <typename T> struct formatter<thousands_view<T>> : formatter<T> { template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
private: private:
detail::dynamic_format_specs<char> specs_; detail::dynamic_format_specs<char> specs_;
@ -2634,7 +2634,7 @@ template <typename T> struct formatter<thousands_view<T>> : formatter<T> {
} }
template <typename FormatContext> template <typename FormatContext>
auto format(thousands_view<T> t, FormatContext& ctx) -> decltype(ctx.out()) { auto format(group_digits_view<T> t, FormatContext& ctx) -> decltype(ctx.out()) {
detail::handle_dynamic_spec<detail::width_checker>(specs_.width, detail::handle_dynamic_spec<detail::width_checker>(specs_.width,
specs_.width_ref, ctx); specs_.width_ref, ctx);
detail::handle_dynamic_spec<detail::precision_checker>( detail::handle_dynamic_spec<detail::precision_checker>(

View File

@ -1595,9 +1595,9 @@ TEST(format_test, bytes) {
EXPECT_EQ(10, s.size()); EXPECT_EQ(10, s.size());
} }
TEST(format_test, thousands) { TEST(format_test, group_digits_view) {
EXPECT_EQ(fmt::format("{}", fmt::thousands(10000000)), "10,000,000"); EXPECT_EQ(fmt::format("{}", fmt::group_digits(10000000)), "10,000,000");
EXPECT_EQ(fmt::format("{:8}", fmt::thousands(1000)), " 1,000"); EXPECT_EQ(fmt::format("{:8}", fmt::group_digits(1000)), " 1,000");
} }
enum test_enum { foo, bar }; enum test_enum { foo, bar };