Hana :: tuple to auto && ... args
Is there a way to use something like:
constexpr auto foo = hana::make_tuple(hana::type_c<Foo1>,hana::type_c<Foo2>);
with something like:
template < typename ... Ts >
struct Final {
constexpr Final(Ts && ... args) {}
};
hana::unpack(foo, [] (auto && ... args) { return Final(args...); });
Because with this code unpack
cannot infer the type of lambda / function. Basically I want to create a type that takes a list of arguments, but I have a tuple that contains the arguments.
source to share
The problem is in your lambda:
[](auto && ... args){ return Final(args...); }
// ~~~~~~~
Final
is not a type, it is a class template. Thus, you need to specify the types explicitly. Something like:
[](auto&&... args){ return Final<decltype(args)...>(
std::forward<decltype(args)>(args)...); }
In C ++ 17, template subtraction for class template parameters Ts&&
does not work as a forwarding reference (see the linked answer ), so the implicit subtraction guide will not match your usage anyway, since you only provide lvalues ββand the guide needs to be reevaluated ... But this would work:
[](auto... args){ return Final(std::move(args)...); }
source to share
If I understand your question correctly, what you are really looking for is
template <typename ...Ts>
struct Final { ... };
constexpr auto foo = hana::make_tuple(hana::type_c<Foo1>,hana::type_c<Foo2>);
auto final_type = hana::unpack(foo, [](auto ...args) {
return Final<typename decltype(args)::type...>;
});
// now, final_type is a hana::type<Final<Foo1, Foo2>>
You can also achieve the same using hana::template_
:
constexpr auto foo = hana::make_tuple(hana::type_c<Foo1>,hana::type_c<Foo2>);
auto final_type = hana::unpack(foo, hana::template_<Final>);
The problem I see with Barry's answer is that you create Final<decltype(hana::type_c<Foo1>), decltype(hana::type_c<Foo2>)>
which is probably not the one you want.
source to share