Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

why this template function fails to compile?

52 views
Skip to first unread message

quanzhou

unread,
Apr 11, 2023, 1:03:21 PM4/11/23
to
#include <concepts>


struct Callback{};

template<typename... Args, std::invocable<Args..., Callback> Func> void reg(Func)
{
}

int main()
{
// good
reg<double, char>([](double, char, Callback) -> void
{
});

// bad
reg([](double, char, Callback)
{
});

return 0;
}

Tried g++-11, error as following:

/usr/include/c++/11/concepts: In substitution of ‘template<class ... Args, class Func> requires invocable<Func, Args ..., Callback> void reg(Func) [with Args = {}; Func = main()::<lambda(double, char, Callback)>]’

See Args get as {} while Func is correct.
What I would like is Args to be {double, char}, why I need to explicitly provide it?

Thanks all you experts.

quanzhou

unread,
Apr 11, 2023, 1:18:50 PM4/11/23
to
I need this Args... type deduction in reg() function because I'm gonna forward it.

Öö Tiib

unread,
Apr 11, 2023, 8:37:01 PM4/11/23
to
On Tuesday, 11 April 2023 at 20:18:50 UTC+3, quanzhou wrote:
> I need this Args... type deduction in reg() function because I'm gonna forward it.

I do not understand what you are trying to do. You are trying to deduce a concept?
But concepts are specification of how *you* plan to use some thing. How
it makes sense to deduce the constraints? Your reg in example code never uses Func
passed to it so it is also not visible to us how you plan to invoke that invocable
Func that has arbitrary list of parameters.

0 new messages