我使用这些类型特征来确定类型是否为动态容器,但是最近在对向量的引用未返回true时陷入混乱。
template<typename T>
struct is_dynamic_container
{
static const bool value = false;
};
template<typename T , typename Alloc>
struct is_dynamic_container<std::vector<T , Alloc>>
{
static const bool value = true;
};
我想我需要使用std::decay
,但是我很难确定是否可以像这样而不是在呼叫站点完成。
template<typename T , typename Alloc>
struct is_dynamic_container<std::decay<std::vector<T , Alloc>>::type>
{
static const bool value = true;
};
^^这不起作用。
我只是想写is_dynamic_container<std::vector<int>&>
而不是写is_dynamic_container<std::decay<std::vector<int>&>::type>
。那可能吗?
template<class T>
using is_dynamic_container_with_decay = is_dynamic_container<std::decay_t<T>>;
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句