模板的C ++ 11 is_same类型特征 [英] C++11 is_same type trait for templates

查看:67
本文介绍了模板的C ++ 11 is_same类型特征的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以检查类型T是任意类型和大小的std::array?

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

但是我想检查Tstd::array的任何实例.如下所示(当然不会编译):

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_same)?

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

推荐答案

您必须自己编写,但这很简单:

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 {};

这篇关于模板的C ++ 11 is_same类型特征的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆