【发布时间】:2016-09-21 13:33:17
【问题描述】:
我在推导 c++ 数组的单个元素的类型时遇到问题。
我想实现以下目标:
template <class T>
struct array_element { };
template <class T>
struct array_element<T[]> {
using type = T;
};
int main() {
int a[5] = {1, 2, 3, 4, 5};
array_element<decltype(a)>::type element = a[0];
}
但是代码显然不能编译(int[5]不匹配T[])...
【问题讨论】:
标签: c++ templates c++11 sfinae typetraits