unqualified-id 如何在函数调用中包含 unqualified-name?
How can a unqualified-id contain a unqualified-name in a function call?
在 C++ 草案 ISO(N4901/2021) 6.5.4(参数相关名称查找)中我们有:
When the postfix-expression in a function call (7.6.1.3) is an
unqualified-id, and unqualified lookup (6.5.3) for the name in the
unqualified-id does not find any
(1.1) — declaration of a class
member, or (1.2) — function declaration inhabiting a block scope, or
(1.3) — declaration not of a function or function template
我想不出一个 unqualified-id 包含 unqualified name 的例子(两者不同) . Draft给出了下面的例子,但是我说不出什么是(f)(s)
:
namespace N {
struct S { };
void f(S);
}
void g() {
N::S s;
f(s); // OK: calls N::f
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
}
I can't figure out a example of an unqualified-id that contains a unqualified name(with the two being different).
措辞中没有说“不合格的名称”。并且似乎在 «name» 之前漏掉了 «component» 这个词。
这是一个例子:
namespace N
{
struct S { };
template<typename>
void f(S);
}
void g()
{
N::S s;
f<int>(s); // OK: ADL finds N::f
}
一个unqualified-id这里是f<int>
(这是一个template-id)并且执行查找它的(组件)名称 f
.
A component name of an unqualified-id U is
— U if it is a name or
— the component name of the template-id or type-name of U, if any.
The component name of a simple-template-id, template-id, or template-name is the first name in it.
术语 «name» 在 [basic.pre]/4 中定义:
A name is an identifier ([lex.name]), operator-function-id ([over.oper]), literal-operator-id ([over.literal]), or conversion-function-id ([class.conv.fct]).
在 C++ 草案 ISO(N4901/2021) 6.5.4(参数相关名称查找)中我们有:
When the postfix-expression in a function call (7.6.1.3) is an unqualified-id, and unqualified lookup (6.5.3) for the name in the unqualified-id does not find any (1.1) — declaration of a class member, or (1.2) — function declaration inhabiting a block scope, or (1.3) — declaration not of a function or function template
我想不出一个 unqualified-id 包含 unqualified name 的例子(两者不同) . Draft给出了下面的例子,但是我说不出什么是(f)(s)
:
namespace N {
struct S { };
void f(S);
}
void g() {
N::S s;
f(s); // OK: calls N::f
(f)(s); // error: N::f not considered; parentheses prevent argument-dependent lookup
}
I can't figure out a example of an unqualified-id that contains a unqualified name(with the two being different).
措辞中没有说“不合格的名称”。并且似乎在 «name» 之前漏掉了 «component» 这个词。
这是一个例子:
namespace N
{
struct S { };
template<typename>
void f(S);
}
void g()
{
N::S s;
f<int>(s); // OK: ADL finds N::f
}
一个unqualified-id这里是f<int>
(这是一个template-id)并且执行查找它的(组件)名称 f
.
A component name of an unqualified-id U is
— U if it is a name or
— the component name of the template-id or type-name of U, if any.
The component name of a simple-template-id, template-id, or template-name is the first name in it.
术语 «name» 在 [basic.pre]/4 中定义:
A name is an identifier ([lex.name]), operator-function-id ([over.oper]), literal-operator-id ([over.literal]), or conversion-function-id ([class.conv.fct]).