为什么编译器不能匹配FunctionF
中的模板参数。invoke()
有没有我不知道的非推断上下文?以及如何解决?
// Invoke Function with all tuple arguments.
template<typename F, size_t... Is, typename Tuple>
auto invoke(F&& f, std::index_sequence<Is...>, Tuple&& t)
{
return f(std::get<Is>(t)...);
}
template<typename F, typename Tuple>
auto invoke(F&& f, Tuple&& t)
{
constexpr std::size_t uiLength = std::tuple_size_v<std::remove_reference_t<Tuple>>;
return invoke(std::forward<F>(f),
std::make_index_sequence<uiLength>{},
std::forward<Tuple>(t));
}
template<typename T>
struct A{
using D = int;
};
template<typename... T>
auto make(T&...){
return std::make_tuple(A<T>{}...);
}
int main()
{
invoke([](auto&, auto&){}, std::make_tuple(A<int>{}, A<double>{})); // works
//auto a = invoke(make, std::make_tuple(A<int>{}, A<double>{})); // does not compile, but why??
}