Jon*_*han 3 c++ templates partial-specialization type-traits c++11
我创建了这些类型特征来确定类型是否是动态容器,但是当对向量的引用未返回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;
};
Run Code Online (Sandbox Code Playgroud)
我想我需要使用std::decay,但我无法弄清楚是否可以这样做而不是在呼叫站点.
template<typename T , typename Alloc>
struct is_dynamic_container<std::decay<std::vector<T , Alloc>>::type>
{
static const bool value = true;
};
Run Code Online (Sandbox Code Playgroud)
^^这不起作用.
我只想写能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>>;
Run Code Online (Sandbox Code Playgroud)