部分专注于错误类型的非类型模板参数

时间:2016-06-05 16:22:06

标签: c++ templates c++11 language-lawyer type-parameter

请考虑以下事项:

template <unsigned >
struct uint_ { };

template <class >
struct X {
    static constexpr bool value = false;
};

template <int I> // NB: int, not unsigned
struct X<uint_<I>> {
    static constexpr bool value = true;
};

int main() {
    static_assert(X<uint_<0>>::value, "!");
}

clang编译代码,gcc不编译。

但是,在以下高度相关的例子中:

template <unsigned >
struct uint_ { };

template <int I> // NB: int, not unsigned
void foo(uint_<I> ) { }

int main() {
    foo(uint_<0>{} );
}

两个编译器都拒绝,没有匹配函数调用foo。 gcc的行为是一致的,clang不是 - 所以一个或另一个编译器有一个或两个例子的错误。哪个编译器是正确的?

1 个答案:

答案 0 :(得分:7)

海湾合作委员会是正确的。 [temp.deduct.type]/17

  

如果P的表单包含<i>,并且表单的类型为A   相应的i值与line=(some pixel values); cc=bwconncomps(bwimage); tempvar=[]; for i=1:length(bwconncomps) tempvar=find(cc.PixelIdxList{i}==line); end [~ answer]=max(tempvar); 的类型不同,扣除失败。

相关问题