我有以下问题:

template< typename callable, typename T , size_t... N_i>
void foo()
{
  using callable_out_type =  std::result_of_t< callable( /* T , ... , T <- sizeof...(N_i) many */ ) >;

  // ...
}

我想得到callable的结果类型,该类型将sizeof...(N_i)的许多参数类型为T作为其输入,例如callable(1,2,3)T==int的情况下的sizeof...(N_i)==3。如何实现呢?

提前谢谢了。

最佳答案

为什么不简单使用:

using callable_out_type = std::result_of_t< callable( decltype(N_i, std::declval<T>())...) >;

您还可以使用从Columbo's answer借来的技巧:
using callable_out_type =  std::result_of_t< callable(std::tuple_element_t<(N_i, 0), std::tuple<T>>...) >;

甚至:
using callable_out_type =  std::result_of_t< callable(std::enable_if_t<(N_i, true), T>...) >;

07-24 09:45
查看更多