Title
Should concept formattable<T, charT> default to char?
Status
nad
Section
[format.formattable]
Submitter
Jonathan Wakely

Created on 2022-10-28.00:00:00 last changed 15 months ago

Messages

Date: 2023-01-24.10:14:05

Proposed resolution:

This wording is relative to N4917.

  1. Modify [format.syn] as indicated:

    […]
    // [format.formatter], formatter
    template<class T, class charT = char> struct formatter;
    
    // [format.formattable], concept formattable
    template<class T, class charT = char>
      concept formattable = see below;
    […]
    
  2. Modify [format.formattable] as indicated:

    [Drafting note: This repeats the default template argument already shown in the synopsis, which would not be valid in C++ code. That is consistent with our presentation style though, as this is not C++ code, it's a specification. See e.g. indirect_strict_weak_order and subrange.]

    -1- Let fmt-iter-for<charT> be an unspecified type that models output_iterator<const charT&> ([iterator.concept.output]).

    template<class T, class charT = char>
      concept formattable =
        semiregular<formatter<remove_cvref_t<T>, charT>> &&
        requires(formatter<remove_cvref_t<T>, charT> f,
                 const formatter<remove_cvref_t<T>, charT> cf,
                 T t,
                 basic_format_context<fmt-iter-for<charT>, charT> fc,
                 basic_format_parse_context<charT> pc) {
          { f.parse(pc) } -> same_as<basic_format_parse_context<charT>::iterator>;
          { cf.format(t, fc) } -> same_as<fmt-iter-for<charT>>;
        };
    
Date: 2023-01-24.00:00:00

[ 2023-01-24 LEWG electronic poll; weak consensus to reject the propsed change. ]

Date: 2022-11-30.00:00:00

[ 2022-11-30 LWG telecon. Status changed: Tentatively NAD → NAD. ]

Date: 2022-11-15.00:00:00

[ 2022-11-30; Reflector poll ]

Set status to "Tentatively NAD" after ten votes in reflector poll.

Date: 2022-11-15.00:00:00

[ 2022-11-01; Reflector poll ]

Set priority to 2 after reflector poll. Two votes for NAD, the convenience makes it easier to misuse.

Date: 2022-10-28.00:00:00

For many uses of <format> there's no need to explicitly mention the output type as char. There are either typedefs for char specializations (format_context, format_parse_context, format_args, etc.) or a default template argument (formatter, range_formatter). But for the new formattable concept you always need to specify the character type:

static_assert( std::formattable<int> ); // ill-formed
static_assert( std::formattable<int, char> ); // OK

Should the concept have a default template argument for the second parameter, to make it easier to check whether something is formattable as char?

History
Date User Action Args
2023-01-24 10:14:05adminsetmessages: + msg13214
2022-11-30 17:59:24adminsetmessages: + msg13144
2022-11-30 09:50:07adminsetmessages: + msg13122
2022-11-30 09:50:07adminsetstatus: new -> nad
2022-11-01 17:49:23adminsetmessages: + msg12917
2022-10-29 12:43:40adminsetmessages: + msg12899
2022-10-28 00:00:00admincreate