From 3239c518145bc10a9cf8ffdd42b5a259c71e3045 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Sun, 11 Feb 2018 07:05:14 -0800 Subject: [PATCH] Get rid of generic lambdas --- include/fmt/format.h | 72 ++++++++++++++++++++++++++++++++------------ 1 file changed, 53 insertions(+), 19 deletions(-) diff --git a/include/fmt/format.h b/include/fmt/format.h index 687c1745..62716424 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -2308,14 +2308,33 @@ class basic_writer { } } + struct dec_writer { + unsigned_type abs_value; + unsigned num_digits; + + template + void operator()(It &&it) const { + it = internal::format_decimal(it, abs_value, num_digits); + } + }; + void on_dec() { unsigned num_digits = internal::count_digits(abs_value); writer.write_int(num_digits, get_prefix(), spec, - [this, num_digits](auto &&it) { - it = internal::format_decimal(it, abs_value, num_digits); - }); + dec_writer{abs_value, num_digits}); } + struct hex_writer { + int_writer &self; + unsigned num_digits; + + template + void operator()(It &&it) const { + it = internal::format_uint<4>(it, self.abs_value, num_digits, + self.spec.type() != 'x'); + } + }; + void on_hex() { if (spec.flag(HASH_FLAG)) { prefix[prefix_size++] = '0'; @@ -2323,12 +2342,20 @@ class basic_writer { } unsigned num_digits = count_digits<4>(); writer.write_int(num_digits, get_prefix(), spec, - [this, num_digits](auto &&it) { - it = internal::format_uint<4>(it, abs_value, num_digits, - spec.type() != 'x'); - }); + hex_writer{*this, num_digits}); } + template + struct bin_writer { + unsigned_type abs_value; + unsigned num_digits; + + template + void operator()(It &&it) const { + it = internal::format_uint(it, abs_value, num_digits); + } + }; + void on_bin() { if (spec.flag(HASH_FLAG)) { prefix[prefix_size++] = '0'; @@ -2336,9 +2363,7 @@ class basic_writer { } unsigned num_digits = count_digits<1>(); writer.write_int(num_digits, get_prefix(), spec, - [this, num_digits](auto &&it) { - it = internal::format_uint<1>(it, abs_value, num_digits); - }); + bin_writer<1>{abs_value, num_digits}); } void on_oct() { @@ -2350,21 +2375,30 @@ class basic_writer { prefix[prefix_size++] = '0'; } writer.write_int(num_digits, get_prefix(), spec, - [this, num_digits](auto &&it) { - it = internal::format_uint<3>(it, abs_value, num_digits); - }); + bin_writer<3>{abs_value, num_digits}); } + enum { SEP_SIZE = 1 }; + + struct num_writer { + unsigned_type abs_value; + unsigned size; + char_type sep; + + template + void operator()(It &&it) const { + basic_string_view s(&sep, SEP_SIZE); + it = format_decimal(it, abs_value, size, + internal::add_thousands_sep(s)); + } + }; + void on_num() { unsigned num_digits = internal::count_digits(abs_value); char_type sep = internal::thousands_sep(writer.locale_.get()); - enum { SEP_SIZE = 1 }; unsigned size = num_digits + SEP_SIZE * ((num_digits - 1) / 3); - writer.write_int(size, get_prefix(), spec, [this, size, sep](auto &&it) { - basic_string_view s(&sep, SEP_SIZE); - it = format_decimal(it, abs_value, size, - internal::add_thousands_sep(s)); - }); + writer.write_int(size, get_prefix(), spec, + num_writer{abs_value, size, sep}); } void on_error() {