- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
命名空间 X 中的函数通过自动推导的返回类型从本地定义的枚举类返回一个枚举器。然后将该返回值传递给一个不合格的函数,并且在 g++(7.3、8.2、主干)上,它在 namespace X 中找到该函数。在 clang 上,它给出了一个找不到函数的错误。
我假设它与 ADL 以及函数局部声明的枚举是否在函数的包含命名空间中有关。
哪个编译器是正确的,为什么? (赞赏标准引用。)
namespace X {
template <typename EnumT>
EnumT getA(EnumT) {
return EnumT::A;
}
enum class Foo { B, A, C };
auto getLocalEnumerator() {
enum class Bar { A, B, C };
return Bar::C;
}
}
int main() {
auto e1 = X::Foo::C; // unambiguously in namespace X
auto e2 = X::getLocalEnumerator(); // unsure what namespace this is
auto a1 = getA(e1); // obvious use of ADL
auto a2 = getA(e2); // clang: error, g++: ADL ok
}
在 godbolt 上直播:https://godbolt.org/g/w2DhDm
谢谢!
最佳答案
这是一个 clang 错误。来自 [basic.lookup.argdep]/2 :
The sets of namespaces and classes are determined in the following way: [...] If T is an enumeration type, its associated namespace is the innermost enclosing namespace of its declaration. If it is a class member, its associated class is the member's class; else it has no associated class.
本地枚举 Bar
将最内层的封闭命名空间...作为其关联的命名空间,即 X
。对 getA
的非限定查找未发现任何内容,因此我们继续查看所有参数的所有关联命名空间 - 关联命名空间的集合是 {X}
。在那里查找应该找到 X::getA
。
关于c++ - 函数局部枚举声明和 ADL 的交互,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51867524/
如果我们定义一个像这样的函数 (defun foo(x) (setf x somevalue)) x 定义为局部变量还是全局变量?使用 setf/q 将值设置为全局值。如果它是全局的,谁能告诉我如
仍在学习 MVC3、EF。现在我正在连接到 MySql,但我相信这无关紧要。为简单起见,我决定为我的测试应用程序使用一个数据库,并且我包含了一个类别来区分数据。例如,我有一个新闻、事件、信息和页面类别
假设我定义了以下代码: int *func() { int *p=(int *)malloc(sizeof(int)); // memory is allocated from heap
我正在构建一个小型 PHP MVC,但我在一小部分编码方面碰壁了。我想我需要“局部 View ”,但我也许可以用现有代码实现一些东西。 目前我的 Controller 是最简单的形式: 实例化一个对象
假设我定义了以下代码: int *func() { int *p=(int *)malloc(sizeof(int)); // memory is allocated from heap
我有以下代码(用 Python 2.X 编写): def banana(x): def apple(stuff): x /= 10 return stuff -
我正在尝试重用一些代码,部分 View 似乎是使用 MVC 时执行此操作的最佳方式。 我创建了一个继承自 IEnumerable 的局部 View (见下文)。 @model IEnumerable
局部 const 变量将存储在哪里?我已经验证过,函数中使用 const 变量的每个位置都会被其值替换(如立即值寻址模式)。但如果指针被分配给它,那么它就会存储在堆栈中。在这里我不明白处理器如何知道其
我想将局部变量用作全局变量,有人告诉我这样做的方法是在函数外部创建变量,如下所示: var foo = null; function bar() {
我正在处理一个很长的 Angular 表格。我想知道我是否可以将它分成许多不同的 View 并在主视图中引用它们中的每一个。 First Section
我有一个导航栏,它是一个局部 View ,我需要在设计页面上呈现它,以便用户编辑他们的个人资料。事实上,我只有一个页面,但是添加执行帐户维护的路径搞乱了我的导航栏加载,因为实例变量不存在。无论如何,我
我没有用到全局变量,也从未明确定义过全局变量,但我的代码中似乎有一个。你能帮我把它做成本地的吗? def algo(X): # randomized algorithm while len(X
假设我有这个(当前无返回)函数: def codepoint_convert(text, offset): codepoint = text[offset] if codepoint
我在我的项目中同时使用了局部 View 和布局概念,但我无法区分。但我的感觉是两者都在做同样的工作。任何人都可以通过示例说出有关局部 View 和布局的简要概念以及区别吗? 最佳答案 除了 Josh
使用全局变量会加快速度吗?在英特尔的体系结构软件开发人员手册(关于微处理器)中建议使用局部变量而不是全局变量。但是,请考虑以下代码: void process_tcp_packets(void) {
我有一个局部 View 使用的模型与我在其中呈现它的 View 不同。我不断收到错误消息。 The model item passed into the dictionary is of type '
我在 cshtml 页面上有一个局部 View ,如下所示:- @model MvcCommons.ViewModels.CompositeViewModel @{ ViewBag.Title = "
我在从 while 循环全局更新数组时遇到问题,如下所述。请注意,我只能使用 C 95 及之前版本的功能。任何帮助将不胜感激!满浆箱http://pastebin.com/ss6VgTCD 在我的程序
我想刷新 Json 局部 View 。我正在尝试使用这个: $('#example123').load('@Url.Action("Rejestracja", "Logowanie")'); 但不能正
我有一个 asp.net 页面,它返回我当前正在使用的选项卡中的部分 View 。我已经设置了所有 jQuery 并且可以正常工作。它工作一次并通过 ajax 返回一个局部 View .html(re
我是一名优秀的程序员,十分优秀!