C++ 在编译时生成T类型的序列

C++ 在编译时生成T类型的序列,c++,c++14,callable,C++,C++14,Callable,我有以下问题: 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 */ ) >; // ... } template void foo() { 使用callable_out_type

我有以下问题:

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 */ ) >;

  // ...
}
template
void foo()
{
使用callable_out_type=std::result_of_t
我想得到
callable
的结果类型,它将
sizeof…(N_I)
类型
T
的许多参数作为其输入,例如,
callable(1,2,3)
T==int
sizeof…(N_I)==3
的情况下,这是如何实现的


非常感谢。

我们可以使用类型别名连接到
N_i
的扩展,但始终返回
T

template <class T, std::size_t>
using eat_int = T;

template< typename callable, typename T , size_t... N_i>
void foo()
{
  using callable_out_type = std::result_of_t< callable(eat_int<T, N_i>...) >;

  // ...
}
模板
使用eat_int=T;
模板
void foo()
{
使用callable_out_type=std::result_of_t);
// ...
}

您可以编写以下帮助程序

template<typename T, size_t>
using type_t = T;

template<typename Callable, typename T, size_t... Is>
auto get_result_of(std::index_sequence<Is...>) -> std::result_of_t<Callable(type_t<T,Is>...)>;

template<typename Callable, typename T, size_t N>
using result_of_n_elements = decltype(get_result_of<Callable, T>(std::make_index_sequence<N>{}));
为什么不简单地使用:

using callable_out_type = std::result_of_t< callable( decltype(N_i, std::declval<T>())...) >;
使用callable_out_type=std::result_of_t
您还可以使用以下技巧:

使用callable\u out\u type=std::result\u of\u t);
甚至:

using callable_out_type =  std::result_of_t< callable(std::enable_if_t<(N_i, true), T>...) >;
使用callable_out_type=std::result_of_t);
也许看一下会有帮助。
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>...) >;