请问c语言中,使用哪种返回类型和参数类型的函数模板可以构成一个长尾词?
- 内容介绍
- 文章标签
- 相关推荐
本文共计248个文字,预计阅读时间需要1分钟。
参考英文答案+函数模板+返回类型推断5个+是否有可能找出函数的返回类型和参数类型并将其用作模板类型?请考虑以下示例:template { // Some code } int
参见英文答案 > Function template return type deduction5个是否有可能找出函数的返回类型和参数类型并将它们用作模板类型?请考虑以下示例:
template <typename ret, typename in> class Bar { // Some code } int foo(float x) { return 0; } int main() { Bar<int, float> b; // Can this be done automatically by inspection of foo at compile time? }
我可以使用foo的函数签名来设置Bar的模板类型吗?
是的先生.template <class Function> struct BarFor_; template <class Ret, class In> struct BarFor_<Ret(*)(In)> { using type = Bar<Ret, In>; }; template <auto function> using BarFor = typename BarFor_<decltype(function)>::type;
现在您可以通过以下方式获取类型:
BarFor<foo> b;
See it live on Coliru
本文共计248个文字,预计阅读时间需要1分钟。
参考英文答案+函数模板+返回类型推断5个+是否有可能找出函数的返回类型和参数类型并将其用作模板类型?请考虑以下示例:template { // Some code } int
参见英文答案 > Function template return type deduction5个是否有可能找出函数的返回类型和参数类型并将它们用作模板类型?请考虑以下示例:
template <typename ret, typename in> class Bar { // Some code } int foo(float x) { return 0; } int main() { Bar<int, float> b; // Can this be done automatically by inspection of foo at compile time? }
我可以使用foo的函数签名来设置Bar的模板类型吗?
是的先生.template <class Function> struct BarFor_; template <class Ret, class In> struct BarFor_<Ret(*)(In)> { using type = Bar<Ret, In>; }; template <auto function> using BarFor = typename BarFor_<decltype(function)>::type;
现在您可以通过以下方式获取类型:
BarFor<foo> b;
See it live on Coliru

