CTAD for std::basic_format_args
Jonathan Wakely

Created on 2022-11-03.00:00:00 last changed 3 weeks ago


Date: 2022-11-12.01:08:06

Proposed resolution:

This wording is relative to N4917.

  1. Modify [format.args] as indicated:

    namespace std {
      template<class Context>
      class basic_format_args {
        size_t size_;                           // exposition only
        const basic_format_arg<Context>* data_; // exposition only
        basic_format_args() noexcept;
        template<class... Args>
          basic_format_args(const format-arg-store<Context, Args...>& store) noexcept;
        basic_format_arg<Context> get(size_t i) const noexcept;
      template<class Context, class... Args>
        basic_format_args(format-arg-store<Context, Args...>) -> basic_format_args<Context>;
Date: 2022-11-12.01:08:06

[ Kona 2022-11-12; Set priority to 3, status to LEWG ]

Date: 2022-11-03.00:00:00

It seems desirable for this should work:

auto args_store = std::make_format_args<C>(1,2,3);
// …
std::basic_format_args args = args_store;

i.e. CTAD should deduce the Context argument from the fmt-store-args<C, int, int, int> object returned by make_format_args.

Another example (from Tomasz Kami&nacute;ski):


template<typename Context>
void foo(basic_format_args<Context> c);

foo(make_format_args<SomeContext>(…)); // won't work
foo(basic_format_args(make_format_args<SomeContext>(…))); // should work

Since fmt-store-args is exposition-only, it's not entirely clear that it must have exactly the form shown in [format.arg.store]. E.g. maybe it can have different template arguments, or could be a nested type defined inside basic_format_args. I don't know how much of the exposition-only spec is actually required for conformance. If CTAD is already intended to be required, it's a bit subtle.

If we want the CTAD to work (and I think it's nice if it does) we could make that explicit by adding a deduction guide.

Date User Action Args
2022-11-12 01:08:06adminsetmessages: + msg13032
2022-11-12 01:08:06adminsetstatus: new -> lewg
2022-11-05 14:29:52adminsetmessages: + msg12929
2022-11-03 00:00:00admincreate