本文介绍了不匹配`int`和`size_t`不匹配的部分模板专业化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
参考以下代码
#include <utility>
#include <cassert>
template <typename T>
struct Wot;
template <int... ints>
struct Wot<std::index_sequence<ints...>> {};
int main() {
assert(sizeof(Wot<std::index_sequence<1, 2, 3>>) == 1);
}
这适用于clang,但不适用于gcc,当我更改部分专业化的类型以在索引序列中接受std::size_t
时,它却起作用.
This works on clang but does not work on gcc, when I change the type of the partial specialization to accept std::size_t
in the index sequence however it works.
谁是对的? lang还是gcc?
Who is right? Clang or gcc?
请在此处 https://wandbox.org/permlink/5YkuimK1pH3aKJT4
推荐答案
gcc是正确的.这正是 [temp.deduct.type]/18 :
gcc is right. This is exactly [temp.deduct.type]/18:
template<int i> class A { /* ... */ };
template<short s> void f(A<s>);
void k1() {
A<1> a;
f(a); // error: deduction fails for conversion from int to short
f<1>(a); // OK
}
template<const short cs> class B { };
template<short s> void g(B<s>);
void k2() {
B<1> b;
g(b); // OK: cv-qualifiers are ignored on template parameter types
}
-举个例子]
镜像示例并简化原始问题:
Mirroring the example and simplifying the original question:
template <class T> struct Wot { };
template <int... ints>
void foo(Wot<std::index_sequence<ints...>> ) { }
int main() {
foo(Wot<std::index_sequence<1, 2, 3>>{}); // error
foo<1, 2, 3>({}); // ok
}
我认为这是clang错误 16279
I think this is clang bug 16279
这篇关于不匹配`int`和`size_t`不匹配的部分模板专业化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!