mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-25 19:50:05 +00:00
thousands -> group_digits
This commit is contained in:
parent
c4d0f96a6d
commit
3940de5952
@ -2611,14 +2611,14 @@ template <> struct formatter<bytes> {
|
||||
}
|
||||
};
|
||||
|
||||
// thousands_view is not derived from view because it copies the argument.
|
||||
template <typename T> struct thousands_view { T value; };
|
||||
// group_digits_view is not derived from view because it copies the argument.
|
||||
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};
|
||||
}
|
||||
|
||||
template <typename T> struct formatter<thousands_view<T>> : formatter<T> {
|
||||
template <typename T> struct formatter<group_digits_view<T>> : formatter<T> {
|
||||
private:
|
||||
detail::dynamic_format_specs<char> specs_;
|
||||
|
||||
@ -2634,7 +2634,7 @@ template <typename T> struct formatter<thousands_view<T>> : formatter<T> {
|
||||
}
|
||||
|
||||
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,
|
||||
specs_.width_ref, ctx);
|
||||
detail::handle_dynamic_spec<detail::precision_checker>(
|
||||
|
@ -1595,9 +1595,9 @@ TEST(format_test, bytes) {
|
||||
EXPECT_EQ(10, s.size());
|
||||
}
|
||||
|
||||
TEST(format_test, thousands) {
|
||||
EXPECT_EQ(fmt::format("{}", fmt::thousands(10000000)), "10,000,000");
|
||||
EXPECT_EQ(fmt::format("{:8}", fmt::thousands(1000)), " 1,000");
|
||||
TEST(format_test, group_digits_view) {
|
||||
EXPECT_EQ(fmt::format("{}", fmt::group_digits(10000000)), "10,000,000");
|
||||
EXPECT_EQ(fmt::format("{:8}", fmt::group_digits(1000)), " 1,000");
|
||||
}
|
||||
|
||||
enum test_enum { foo, bar };
|
||||
|
Loading…
Reference in New Issue
Block a user