c – 在编译时生成类型为T的序列
发布时间:2020-12-16 07:53:44 所属栏目:百科 来源:网络整理
导读:我有以下问题: template typename callable,typename T,size_t... N_ivoid foo(){ using callable_out_type = std::result_of_t callable( /* T,...,T - sizeof...(N_i) many */ ) ; // ...} 我想获取可调用的结果类型,它使用sizeof …(N_i)类型T的许多参数
我有以下问题:
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 */ ) >; // ... } 我想获取可调用的结果类型,它使用sizeof …(N_i)类型T的许多参数作为其输入,例如,在T == int和sizeof …的情况下可调用(1,2,3) (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>...) >; (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |