今天,我正在阅读clang的C++ 17支持页面。我注意到有些奇怪。将功能与模板模板参数匹配到兼容参数(P0522R0)标记为部分,因为必须通过开关将其激活。他们的注释says:
Despite being the the resolution to a Defect Report, this feature is disabled by default in all language versions, and can be enabled explicitly with the flag -frelaxed-template-template-args in Clang 4. The change to the standard lacks a corresponding change for template partial ordering, resulting in ambiguity errors for reasonable and previously-valid code. This issue is expected to be rectified soon.
激活此功能后会破坏哪种构造?为什么会破坏代码以及如何破坏代码?
最佳答案
您可以具有如下代码:
template<template<typename> typename>
struct Foo {};
template<typename, typename = void>
struct Bar {};
Foo<Bar> unused;
如果没有缺陷解决方案,则
unused
会格式错误,因为foo
采用的模板只有一个模板参数,而不是两个。如果您依赖于此(对于SFINAE而言):template<template<typename> typename>
void foo();
template<template<typename, typename> typename>
void foo();
template<typename, typename = void>
struct Bar {};
int main() {
foo<Bar>(); // ambiguous after resolution!
}
然后, call 将失败!问题在于部分排序没有相应的更改,因此两个候选函数都具有相同的生存能力,并且调用不明确。
关于c++ - P0522R0的中断代码如何?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62847485/