3.4.2来自n3290草稿的依赖于参数的名称查找 [英] 3.4.2 Argument-dependent name lookup from n3290 Draft
问题描述
ISO草案n3290第3.4.2节第1段中的一点:
A point from ISO draft n3290 section 3.4.2 paragraph 1:
当 postfix-expression 在函数调用中是非限定id,可以搜索在通常的无限额查找期间未考虑的其他命名空间,并且在那些命名空间中,可以找到不另外可见的命名空间范围友元函数声明。对搜索的这些修改取决于参数的类型(以及模板模板参数,模板参数的命名空间)。
When the postfix-expression in a function call is an unqualified-id, other namespaces not considered during the usual unqualified lookup may be searched, and in those namespaces, namespace-scope friend function declarations not otherwise visible may be found. These modifications to the search depend on the types of the arguments (and for template template arguments, the namespace of the template argument).
在这里他们说搜索的这些修改取决于参数/模板模板参数的类型/模板参数的命名空间...任何一个expalin与一个例子可以吗?我试过与argumetn types..please expalin模板模板参数类型&模板参数类型的命名空间
Here they said aboout "these modifications to the search depend on the types of the arguments / template template arguments / namespace of the template argument " ...Can any one expalin with an example please? I tried with argumetn types..please expalin with template template argument types & namespace of the template argument type
推荐答案
考虑一个简单的非限定函数调用:
Consider a simple unqualified function call:
foo(x);
ADL意味着 foo
只是在封闭范围中,以及调用所在的命名空间,而且还包含 x
类型的命名空间。例如如果 x
是 std :: vector< int>
then namespace std
也被搜索。因此:
ADL means that foo
is looked up not just in the enclosing scope, and the namespace that the call is in, but also the namespace of the type of x
. e.g. if x
is a std::vector<int>
then namespace std
is also searched. Thus:
int main() {
std::vector<int> x,y;
swap(x,y);
}
可以,并且会调用 std :: swap ()
。
查找也取决于任何模板参数的命名空间,因此如果 x
是 std :: vector< mynamespace :: myclass>
然后 mynamespace
因此
The lookup also depends on the namespace of any template arguments too, so if x
is std::vector<mynamespace::myclass>
then mynamespace
is also included in the lookup. Thus
namespace mynamespace {
struct myclass {};
void foo(std::vector<mynamespace::myclass> const&){}
}
int main() {
std::vector<mynamespace::myclass> x;
foo(x);
}
将调用 mynamespace :: foo code>。
will call mynamespace::foo()
.
最后,查找还扩展到用作模板模板参数的任何模板的命名空间。例如
Finally, the lookup also extends to the namespaces of any templates used as template template parameters. e.g.
namespace mynamespace {
template<typename T>
struct mytemplate
{};
template<typename T>
void bar(T const&) {}
}
template<template<typename> class T>
struct wrapper {};
int main() {
wrapper<mynamespace::mytemplate> x;
bar(x);
}
即使 wrapper
因为用于 x
的模板模板参数为,所以将找到
。 mynamespace :: bar
code> mynamespace :: mytemplate
Even though wrapper
is in the global namespace, mynamespace::bar
will be found, because the template template parameter used for x
is mynamespace::mytemplate
.
这篇关于3.4.2来自n3290草稿的依赖于参数的名称查找的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!