I made these type traits to determine if the type is a dynamic container, but recently ran into confusion when a reference to a vector didn't return 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;
};
I think I need to use std::decay
, but I'm having trouble figuring out if it can be done like this rather than at the call site.
template<typename T , typename Alloc>
struct is_dynamic_container<std::decay<std::vector<T , Alloc>>::type>
{
static const bool value = true;
};
^^This doesn't work.
I just want to be able to write is_dynamic_container<std::vector<int>&>
and not is_dynamic_container<std::decay<std::vector<int>&>::type>
. Is that possible?
template<class T>
using is_dynamic_container_with_decay = is_dynamic_container<std::decay_t<T>>;