来自iso c++ n3290的一点:参数依赖的名称查找:
A point from iso C++ n3290 : Argument dependant Name Lookup:
来自iso c++ n3290的一个点:参数依赖的名称查找:第3.4.2节,第4段
When considering an associated namespace, the lookup is the same as the lookup
performed when the associated namespace is used as a qualifier (3.4.3.2) except
that:
— Any using-directives in the associated namespace are ignored.
— Any namespace-scope friend functions or **friend function templates** declared
in associated classes are visible within their respective namespaces even if
they are not visible during an ordinary lookup (11.3).
— All names except those of(possibly overloaded) functions and function
templates are ignored.
与2003年的标准相比,他增加了第三点。谁能解释一下……用示例解释....(重载)..
他还说,在第二点中,他包括了友元函数模板(我知道norml类友元函数)。
我认为查找应该一直这样工作,更多的是澄清而不是实际的变化。我不确定是否添加了它,因为其他地方添加了一些其他措辞,需要使这更清楚,编译器实际上在一些角落情况下有所不同,或者一些机构质疑什么是正确的实现。
Ad点2。就像你可以声明函数f是类c的友元一样,你也可以声明函数模板t是类c的友元。声明是不同的,因为它显式地提到了模板参数,所以他们觉得有必要显式地适用于两种情况。
template <typename T> bool f(T);
class c {
friend bool f<c>(c); // only particular instantiation is friend
template <typename T> friend bool f<T>(T); // all instantiations are friends
}
(当然,您可以将它与c
作为模板本身结合起来,以获得无限的乐趣)。
广告点3。该子句意味着,如果在包含类f的名称空间n中查找函数f,则不会考虑类f(而如果编写n::f,则会取该类)。"可能超载"并不一定要出现。函数总是可以重载的,并且在所有命名空间中发现的所有重载都将包含在最终的重载解析中。
namespace n {
class c { ... };
class e { ... } f;
}
namespace o {
class d { ... };
void f(c &, d &) { ... };
void f(c &, d &, bool) { ... };
}
namespace p {
f(c(), d());
}
f(c(), d())
关联的命名空间同时为n
和o
。然而,n::f
不是一个函数,而是一个(可能是函子)实例,因此不考虑它(而旧的措辞允许考虑f
的operator()
)。o::f
被重载,所有的重载都被考虑(并且,在收集了f的所有可能的含义之后,3参数的变体被排除,因为只给出了2个参数)。
相关文章:
- 通过依赖类型使用非类型模板参数的单类型模板参数类模板的部分专用化
- 类成员函数参数列表是否可以依赖于模板参数?
- 如何定义依赖于参数包转换的函数的返回类型
- 引用非依赖名称而不指定模板参数
- C++ 使函数调用依赖于模板参数
- 如何初始化依赖于先前条目的可变参数模板?
- 如何修复"没有依赖于模板参数的参数'glGenVertexArrays'......"C++ 中的错误
- 依赖的非类型参数包:标准怎么说?
- 运算符<<依赖于参数的查找不在全局命名空间中查找
- 依赖于其他模板参数的模板参数
- 使用不依赖于方法模板参数的enable_if
- 如何定义具有依赖于符号调试的参数的函数
- 如何让成员函数实现依赖于类的模板参数?
- 如何避免参数数量依赖于条件的调用分支?
- 为什么在这种情况下不考虑依赖于参数的查找?
- 如何定义依赖于模板参数的类型定义
- 传递具有依赖嵌套参数类型的模板模板参数时出错
- 模板内依赖参数的查找
- 应用非限定名称查找,而不是依赖参数的名称查找
- c++中依赖参数的名称查找:来自n3290草案的点