|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4246" status="New"> |
| 5 | +<title>Redundant constraint in `range_formatter::format`</title> |
| 6 | +<section> |
| 7 | +<sref ref="[format.range.formatter]"/> |
| 8 | +</section> |
| 9 | +<submitter>Hewill Kang</submitter> |
| 10 | +<date>18 Apr 2025</date> |
| 11 | +<priority>99</priority> |
| 12 | + |
| 13 | +<discussion> |
| 14 | +<p> |
| 15 | +Currently, the signature of `range_formatter::format` is as follows: |
| 16 | +</p> |
| 17 | +<blockquote><pre> |
| 18 | +template<ranges::input_range R, class FormatContext> |
| 19 | + requires formattable<ranges::range_reference_t<R>, charT> && |
| 20 | + same_as<remove_cvref_t<ranges::range_reference_t<R>>, T> |
| 21 | +typename FormatContext::iterator |
| 22 | + format(R&& r, FormatContext& ctx) const; |
| 23 | +</pre></blockquote> |
| 24 | +<p> |
| 25 | +which requires that the reference type of the range parameter must be `formattable`, |
| 26 | +and such type must be exactly `T` after removing the <i>cvref</i>-qualifiers. |
| 27 | +</p> |
| 28 | +<p> |
| 29 | +However, satisfying the latter always implies satisfying the former, as the `range_formatter` class |
| 30 | +already requires that `T` must be `formattable`. |
| 31 | +</p> |
| 32 | +<p> |
| 33 | +There is no need to perform a redundant check here. |
| 34 | +</p> |
| 35 | +</discussion> |
| 36 | + |
| 37 | +<resolution> |
| 38 | +<p> |
| 39 | +This wording is relative to <paper num="N5008"/>. |
| 40 | +</p> |
| 41 | + |
| 42 | +<ol> |
| 43 | + |
| 44 | +<li><p>Modify <sref ref="[format.range.formatter]"/> as indicated:</p> |
| 45 | + |
| 46 | +<blockquote> |
| 47 | +<blockquote> |
| 48 | +<pre> |
| 49 | +namespace std { |
| 50 | + template<class T, class charT = char> |
| 51 | + requires same_as<remove_cvref_t<T>, T> && formattable<T, charT> |
| 52 | + class range_formatter { |
| 53 | + […] |
| 54 | + template<ranges::input_range R, class FormatContext> |
| 55 | + requires <del>formattable<ranges::range_reference_t<R>, charT> &&</del> |
| 56 | + same_as<remove_cvref_t<ranges::range_reference_t<R>>, T> |
| 57 | + typename FormatContext::iterator |
| 58 | + format(R&& r, FormatContext& ctx) const; |
| 59 | + }; |
| 60 | +} |
| 61 | +</pre> |
| 62 | +</blockquote> |
| 63 | +[…] |
| 64 | +<pre> |
| 65 | +template<ranges::input_range R, class FormatContext> |
| 66 | + requires <del>formattable<ranges::range_reference_t<R>, charT> &&</del> |
| 67 | + same_as<remove_cvref_t<ranges::range_reference_t<R>>, T> |
| 68 | +typename FormatContext::iterator |
| 69 | + format(R&& r, FormatContext& ctx) const; |
| 70 | +</pre> |
| 71 | +<blockquote> |
| 72 | +<p> |
| 73 | +-11- <i>Effects</i>: Writes the following into <code>ctx.out()</code>, adjusted according to the |
| 74 | +<i>range-format-spec</i>: |
| 75 | +</p> |
| 76 | +</blockquote> |
| 77 | +</blockquote> |
| 78 | + |
| 79 | +</li> |
| 80 | + |
| 81 | +</ol> |
| 82 | +</resolution> |
| 83 | + |
| 84 | +</issue> |
0 commit comments