C++ Logo


Advanced search

Re: [std-proposals] Proposal to allow multiple template parameter packs for class templates provided they can be deduced using CTAD

From: Jason McKesson <jmckesson_at_[hidden]>
Date: Sun, 30 Apr 2023 09:54:02 -0400
On Sun, Apr 30, 2023 at 9:26 AM Anoop Rana <ranaanoop986_at_[hidden]> wrote:
> @Barry Revzin
>> Also why isn't it sufficient to do this:
>> template <typename F, typename... Args>
>> struct C;
>> template <typename... Param, typename Ret, typename... Args>
>> struct C<Ret(*)(Param...), Args...>
>> {
>> C(Ret (*ptrFunc)(const Param&... param), const Args&... args);
>> };
>> Which is valid today?
> I don't think this will work as you expect it to work. Can you give an example of a working demo where the template arguments are deduced from constructor arguments/parameters using CTAD. For example something like C c(somefunctionname, 5,5); where we don't have to specify the arguments when creating an instance. The point is that they should be deduced from constructor arguments using CTAD

As I mentioned, you need a template deduction guide to make it work.
Like this https://gcc.godbolt.org/z/Mz57vj7Ps

template <typename... Param, typename Ret, typename... Args>
C(Ret(*ptr)(Param...), Args...) -> C<decltype(ptr), Args...>;

Received on 2023-04-30 13:54:14