Title
CTAD for std::basic_format_args
Status
c++23
Section
[format.args]
Submitter
Jonathan Wakely

Created on 2022-11-03.00:00:00 last changed 5 months ago

Messages

Date: 2023-02-13.11:31:32

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
    
      public:
        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: 2023-02-13.00:00:00

[ 2023-02-13 Approved at February 2023 meeting in Issaquah. Status changed: Immediate → WP. ]

Date: 2023-02-07.01:47:11

[ Issaquah 2023-02-06; LWG ]

Unanimous consent (9/0/0) to move to Immediate for C++23.

Date: 2023-01-15.00:00:00

[ 2023-01-10; LEWG telecon ]

Unanimous consensus in favor.

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):

Given:

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.

History
Date User Action Args
2023-11-22 15:47:43adminsetstatus: wp -> c++23
2023-02-13 11:31:32adminsetmessages: + msg13387
2023-02-13 11:31:32adminsetstatus: immediate -> wp
2023-02-07 01:47:11adminsetmessages: + msg13282
2023-02-07 01:47:11adminsetmessages: + msg13281
2023-02-07 01:47:11adminsetstatus: lewg -> immediate
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