使用函数调用运算符作为模板参数的官方名称是什么?

huangapple go评论69阅读模式
英文:

What's the offical name of using function call operator as template argument

问题

我试图使用类型特性与函数对象,以下是代码:

struct fun {
  template <class T>
  constexpr auto operator()(T a) const  {
    return 0;
  }
};

template<class T> 
struct types{};

我好奇types<fun(int)>的官方名称是什么,可能是获取函数调用运算符的类型吗?

英文:

I'm trying to use type trait with functor, below is the code:

struct fun {
  template &lt;class T&gt;
  constexpr auto operator()(T a) const  {
    return 0;
  }
};

template&lt;class T&gt; 
struct types{};

I'm curious about what's the official name of the usage types&lt;fun(int)&gt;, probably getting the type of the function call operator?

答案1

得分: 1

fun(int) 是一个接受 int 并返回 fun 类型的函数类型。

它与 fun::operator() 无关。

英文:

fun(int) is the type of a function that takes an int and returns a fun.

It is unrelated to fun::operator().

答案2

得分: 1

"types<fun(int)>"被称为模板标识

模板标识由两个部分组成:

  1. 模板名称:在您的示例中为types

  2. 参数列表:在您的示例中为fun(int),它本身是一个函数类型。

英文:

> what's the official name of the usage types&lt;fun(int)&gt;

It (types&lt;fun(int)&gt;) is called a template-id:

> <h4>template-id</h4>
>
>
&gt; template-name &lt;parameter-list &gt;
&gt;


As you can see the template-id consists of 2 parts:

  1. template-name: which is types in your example.

  2. parameter-list: which is fun(int) which itself is a function type in your example.

huangapple
  • 本文由 发表于 2023年5月25日 10:41:21
  • 转载请务必保留本文链接:https://go.coder-hub.com/76328566.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定