What are the constraints on the template parameter of basic_format_arg?
Richard Smith

Created on 2019-08-01.00:00:00, last changed 2019-08-03.18:53:28.


Date: 2019-08-03.18:53:28

Proposed resolution:

This wording is relative to the Post Cologne working draft.

  1. Modify [format.arg] as indicated:

    template<class T> explicit basic_format_arg(const T& v) noexcept;

    -?- Constraints: The template specialization typename Context::template formatter_type<T> is an enabled specialization of formattermeets the Formatter requirements ([formatter.requirements]). The extent to which an implementation determines that typename Context::template formatter_type<T> is enabledmeets the Formatter requirements is unspecified, except that as a minimum the expression typename Context::template formatter_type<T>().format(declval<const T&>(), declval<Context&>()) shall be well-formed when treated as an unevaluated operand.

Date: 2019-08-01.00:00:00

In P0645R10 20.?.5.1/ we find:

Constraints: typename Context::template formatter_type<T> is enabled.

… which doesn't mean anything, because that is an arbitrary type. Presumably the intent is that that type will always be a specialization of formatter, but there appear to be no constraints whatsoever on the Context template parameter, so there seems to be no requirement that that is the case.

Should basic_format_arg place some constraints on its Context template parameter? E.g., should it be required to be a specialization of basic_format_context?

Victor Zverovich:

The intent here is to allow different context types provide their own formatter extension types. The default formatter context and extension are basic_format_context and formatter respectively, but it's possible to have other. For example, in the fmt library there is a formatter context that supports printf formatting for legacy code. It cannot use the default formatter specializations because of the different syntax (%... vs {...}).

Richard Smith:

In either case, the specification here seems to be missing the rules for what is a valid Context parameter.

I'm happy to editorially change "is enabled" to "is an enabled specialization of formatter", since there's nothing else that this could mean, but we still need a wording fix for the broader issue here. Here's what I have so far for this wording:

Constraints: The template specialization typename Context::template formatter_type<T> is an enabled specialization of formatter ([formatter.requirements]).

Tim Song:

I think what we actually want here is "typename Context::template formatter_type<T> meets the Formatter requirements".

Date User Action Args
2019-08-03 18:53:28adminsetmessages: + msg10538
2019-08-01 00:00:00admincreate