C++11 is_same type trait for templates

巧了我就是萌 提交于 2019-12-18 10:23:20

问题


Is it possible to check that type T is an std::array of arbitrary type and size?

I can check for a particular array, for instance:

    is_same<T, std::array<int,5>>::value

But I'd like to check that T is any instantiation of std::array. Something like below (which, of course, does not compile):

    is_same<T, std::array>::value

Is there a way to achieve this (maybe not using is_same)?


回答1:


You have to write your own, but it's simple:

template<typename>
struct is_std_array : std::false_type {};

template<typename T, std::size_t N>
struct is_std_array<std::array<T,N>> : std::true_type {};


来源:https://stackoverflow.com/questions/16905359/c11-is-same-type-trait-for-templates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!