- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
Gcc 可以正常编译,但 Clang(主干)拒绝并显示以下消息:
<source>:7:8: error: class template partial specialization is not more specialized than the primary template [-Winvalid-partial-specialization]
template<class T, T x>
struct S{};
template<int& x>
struct S<int&, x> { };
这段代码是否正确?
最佳答案
这仅在 -std=c++17
及更高版本中出现。 “更专业”的确定需要 synthesizing a pair of function templates from the class templates , synthesizing unique types, values, and templates for the template parameters ,最后 performing template argument deduction in both directions .如果演绎在一个方向上成功但在另一个方向上失败,则模板“更专业”。
在这里,Clang 从两个来源推导出 T
并得到不同的结果:
int&
,它推导出T := int&
。x
,它根据通常的推导规则(通常不推导引用类型)推导T := int
。这种从非类型模板参数的类型推断的能力是在 C++17 中添加的。这使得推导在两个方向上都失败了,因此部分特化无法通过“更特化”的测试。
这看起来像是标准中的缺陷。解决方法是将原始模板中的 T
包装在非推导上下文中。
关于c++ - Clang 不会编译 gcc 会编译的模板特化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51779059/
关闭。这个问题不符合Stack Overflow guidelines .它目前不接受答案。 我们不允许提问寻求书籍、工具、软件库等的推荐。您可以编辑问题,以便用事实和引用来回答。 关闭 4 年前。
正如您在 this travis.yml 中看到的那样文件,我的代码依赖于一些第三方库,我在构建项目之前将它们安装在远程系统上。 Travis 每次推送提交时都会下载并构建这些库,这可以避免吗?我的意
我是一名优秀的程序员,十分优秀!