Title
Redundant constraint in `range_formatter::format`
Status
new
Section
[format.range.formatter]
Submitter
Hewill Kang

Created on 2025-04-18.00:00:00 last changed 2 weeks ago

Messages

Date: 2025-04-21.10:32:32

Proposed resolution:

This wording is relative to N5008.

  1. Modify [format.range.formatter] as indicated:

    namespace std {
      template<class T, class charT = char>
        requires same_as<remove_cvref_t<T>, T> && formattable<T, charT>
      class range_formatter {
        […]
        template<ranges::input_range R, class FormatContext>
            requires formattable<ranges::range_reference_t<R>, charT> &&
                     same_as<remove_cvref_t<ranges::range_reference_t<R>>, T>
          typename FormatContext::iterator
            format(R&& r, FormatContext& ctx) const;
      };
    }
    
    […]
    template<ranges::input_range R, class FormatContext>
      requires formattable<ranges::range_reference_t<R>, charT> &&
               same_as<remove_cvref_t<ranges::range_reference_t<R>>, T>
    typename FormatContext::iterator
      format(R&& r, FormatContext& ctx) const;
    

    -11- Effects: Writes the following into ctx.out(), adjusted according to the range-format-spec:

Date: 2025-04-18.00:00:00

Currently, the signature of `range_formatter::format` is as follows:

template<ranges::input_range R, class FormatContext>
  requires formattable<ranges::range_reference_t<R>, charT> &&
           same_as<remove_cvref_t<ranges::range_reference_t<R>>, T>
typename FormatContext::iterator
  format(R&& r, FormatContext& ctx) const;

which requires that the reference type of the range parameter must be `formattable`, and such type must be exactly `T` after removing the cvref-qualifiers.

However, satisfying the latter always implies satisfying the former, as the `range_formatter` class already requires that `T` must be `formattable`.

There is no need to perform a redundant check here.

History
Date User Action Args
2025-04-21 10:32:32adminsetmessages: + msg14729
2025-04-18 00:00:00admincreate