我做了這些類型的特徵,以確定類型是否是一個動態容器,但最近遇到一個混淆,當一個向量的引用沒有返回true時。如何在部分特化類型特徵時使用std :: decay?
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>
。那可能嗎?
謝謝。接受這個答案,因爲它是最乾淨的解決方案。簡明扼要。 – Jonathan