From ccb0564bfc2077445173659d91057a0d885a7ab0 Mon Sep 17 00:00:00 2001 From: q66 Date: Sun, 26 Feb 2017 00:29:35 +0100 Subject: [PATCH] clean up range writer --- ostd/format.hh | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/ostd/format.hh b/ostd/format.hh index 994495d..4bfcae1 100644 --- a/ostd/format.hh +++ b/ostd/format.hh @@ -682,7 +682,9 @@ private: throw format_error{"tuples need the '%s' spec"}; } writer.put('{'); - write_range_val(writer, escape, false, "%s", ", ", val); + write_range_val(writer, [&writer, escape](auto const &rval) { + format_spec{'s', escape}.write_arg(writer, 0, rval); + }, ", ", val); writer.put('}'); return; } @@ -775,11 +777,9 @@ private: sp.write_fmt(writer, item); } - template + template void write_range_val( - R &writer, bool escape, bool expandval, string_range ifmt, - string_range sep, - T const &val + R &writer, F &&func, string_range sep, T const &val ) const { if constexpr(detail::iterable_test) { auto range = ostd::iter(val); @@ -787,7 +787,7 @@ private: return; } for (;;) { - write_range_item(writer, escape, expandval, ifmt, range.front()); + func(range.front()); range.pop_front(); if (range.empty()) { break; @@ -812,9 +812,14 @@ private: write_range(writer, idx - 1, expandval, sep, args...); } } else { - write_range_val( - writer, p_gflags & FMT_FLAG_AT, expandval, rest(), sep, val - ); + write_range_val(writer, [ + this, &writer, escape = p_gflags & FMT_FLAG_AT, expandval, + fmt = rest() + ](auto const &rval) { + this->write_range_item( + writer, escape, expandval, fmt, rval + ); + }, sep, val); } }