C++ Logo

std-proposals

Advanced search

Re: Remove restriction on deduction guides.

From: Arthur O'Dwyer <arthur.j.odwyer_at_[hidden]>
Date: Sat, 20 Feb 2021 15:13:20 -0500
On Sat, Feb 20, 2021 at 2:01 PM Jason McKesson via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> On Sat, Feb 20, 2021 at 11:32 AM Arthur O'Dwyer via Std-Proposals <
std-proposals_at_[hidden]> wrote:
> >
> > By the way, another fantasy feature that would solve your problem is
> > if a metafunction could return a first-class pack. Then you could
> > write something like
> >
> > template<class F> receiver(F&&) -> receiver<
> > detail::corresponding_template_args<receiver, F>... >;
> >
> > But of course that doesn't help you today.
>
> I'm not sure how "fantasy" that is, as there have been a number of
> proposals batted around about storing parameter packs and unpacking
> them. It's difficult to track the status of proposals these days, but
> P1858 is being discussed in EWG at present, and P2277 is probably a
> better overview of where things currently stand.

"Fantasy" in the sense of "not standard C++20, not currently draft C++2b,
and maybe never happening."

> In any case, if you can store packs more arbitrarily, such as in a
> template type alias or something, then it should be easy enough to
> have a metafunction that returns a pack given a set of template
> parameters.

Yeah. Here's another worked alternative:
https://godbolt.org/z/sYY1jW

In this example I'm passing around "packs" via this vocabulary type:

template<class... Ts>
struct Pack {
    using type = Pack;
    template<template<class...> class Tpl> using as = Tpl<Ts...>;
};

So for example inside `receiver` we do

    template<class... Ts>
    using VoidFunc = void(Ts...);

    using Func = std::function<typename Pk::as<VoidFunc>>;

to expand the template parameter `Pk=Pack<Ps...>` out into a type of the
form `void(Ps...)`.

–Arthur

Received on 2021-02-20 14:13:33