- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
有3个例子:
我.
typedef int foo;
namespace B
{
struct S
{
operator int(){ return 24; }
};
int foo(B::S s){ return 0; }
}
int main()
{
int t=foo(B::S()); //24, ADL does not apply
}
二.
namespace B
{
struct S
{
operator int(){ return 24; }
};
int foo(B::S s){ return 0; }
}
int main()
{
int t=foo(B::S()); //0, ADL applies
}
三.
namespace B
{
struct S
{
operator int(){ return 24; }
};
int foo(B::S s){ return 0; }
}
int foo(B::S s){ return 12; }
int main()
{
int t=foo(B::S()); //error: call of overloaded ‘foo(B::S)’ is ambiguous
//ADL applies
}
我不清楚 ADL 查找的实际条件是什么?我需要引用标准来描述它。
最佳答案
This Standard paragraph 澄清,甚至有一个非常像你的第一个例子的例子。
3.4.1/3:
The lookup for an unqualified name used as the postfix-expression of a function call is described in 3.4.2 [basic.lookup.argdep]. [Note: For purposes of determining (during parsing) whether an expression is a postfix-expression for a function call, the usual name lookup rules apply. The rules in 3.4.2 have no effect on the syntactic interpretation of an expression. For example,
typedef int f;
namespace N {
struct A {
friend void f(A &);
operator int();
void g(A a) {
int i = f(a); // f is the typedef, not the friend
// function: equivalent to int(a)
}
};
}
Because the expression is not a function call, the argument-dependent name lookup (3.4.2) does not apply and the friend function
f
is not found. -end note]
关于c++ - 什么时候应用 ADL?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32394226/
这个问题在这里已经有了答案: How do I write an ADL-enabled trailing return type, or noexcept specification? (4 个答
例如,我想使用约束来确保函数 isinf为模板参数实现 T .如 T是 float 之一, double , long double或整数类型,这可以通过以下方式完成: #include templ
我在 ADF 中进行自定义事件,其中涉及从 Azure 存储 Blob 读取多个文件,对它们进行一些处理,然后最终将生成的文件写入 Azure Data Lake Store。最后一步是我停止的地方,
我遇到了以下涉及 ADL 和已删除函数的令人困惑的示例: 第一个例子: namespace A { struct S{}; void f(S){cout << "adl" << end
关闭。这个问题需要debugging details .它目前不接受答案。 编辑问题以包含 desired behavior, a specific problem or error, and th
template struct S { bool valid(T a) { return is_valid(a); } }; bool is_valid(int) { return t
我有几个命名空间,每个命名空间都有一个名为 f 的函数模板。 // f() and Widget namespace A { struct Widget { }; template vo
我有一个带有类内定义友元函数的类,我最好不要修改它(它来自已经部署的 header ) #include #include namespace our_namespace { template
我有一个函数模板 printSize 在声明 getSize 之前调用重载函数 getSize。为了让我的程序结构更清晰,我想将两个函数放在不同的命名空间 A 和 B 中,如注释代码行所示。但是,AD
struct S { vector v; void method() { begin(v); } }; 上面的代码片段编译正常,因为 ADL直到我添加
对于非限定名称查找,“通常非限定名称查找”和“参数相关名称查找”(ADL),我无法在标准中找到哪一个先发生? 再次尝试向过载候选集添加一些内容,但顺序似乎并不重要。但仍然很高兴知道哪一个先发生。 谢谢
我试图了解如何 ADL至少它的基础是有效的,并创建了以下代码: #include #include #include using std::pair; using std::string; u
简而言之,我试图了解 C++ 中参数依赖查找的行为。我不清楚 ISO/IEC 14882:2017 (E) 中关于 ADL 的一些陈述。我希望有人能向我澄清它们。 按照标准, Typedef name
可以给我一个不使用模板的 ADL 示例吗?从来没有见过这样的东西。我的意思是像 here .具体来说,我对导致上述一些陷阱的示例感兴趣。 编辑: 我认为 Tomalak 的回答可以延伸到陷阱。考虑一下
有3个例子: 我. typedef int foo; namespace B { struct S { operator int(){ return 24; }
我正在使用 Visual Studio 2010 在 Microsoft Windows 7 上编译 x64 服务,使用 Boost variant像这样的东西: namespace my_ns {
情况是某些成员函数 bar::Bar::frobnicate 想要利用 ADL 在具有相同名称的函数中从某个未知命名空间中查找函数。但是,它只能找到自己的名字。 测试用例 (请注意,实际上,Bar 是
我对 C++ 中的标准 ADL 解析有疑问。 这是解释我的查询的示例代码: #include // The mechanism: namespace A { template ::std::st
这是来自 Does argument dependent lookup only search namespaces or classes too? 的跟进问题,其中@David Rodríguez
这个问题在这里已经有了答案: Why doesn't ADL find function templates? (4 个答案) 关闭 8 年前。 我想明白为什么调用模板f下面不编译: struct
我是一名优秀的程序员,十分优秀!