假设我有这样的设置:
namespace hi {
template<typename L, typename R> L operator+(L l, R r) {
// some body
}
auto f() {
return [] {}; // Legal C++14
}
}
int main() {
auto x = hi::f();
1 + x; // Is this legal?
}
Run Code Online (Sandbox Code Playgroud)
问题是lambda类型上的ADL是否会在Standard中找到该命名空间中的重载运算符.
Nic*_*las 10
C++ 11说(5.1.2,p3)lambda的类型将被声明为" in the smallest block scope, class scope, or namespace scope that contains the corresponding lambda-expression."所以在这种情况下,类型将被声明f.C++ 14的CD具有相同的语言.
所以问题实际上是本地类的命名空间是什么.我不认为它有一个.
C++ 11,第9.8节,p1,声明:The name of a local class is local to its enclosing scope.因此,我不认为它有任何关联的命名空间(根据3.4.2,p2),因此不受ADL的约束.
| 归档时间: |
|
| 查看次数: |
289 次 |
| 最近记录: |