2013-04-20 55 views
2

我有一個模板結構,它接受模板參數的Iterator類型。 現在我需要將這個類專門化爲不同容器的迭代器。 我試圖用的std ::矢量指定容器類型的迭代器類型的部分特化

template<typename Iterator> 
struct AC { 

}; 

template<typename T, typename Alloc> 
struct AC<typename std::vector<T, Alloc>::iterator> { //this doesn't work 

}; 

,但我得到這個編譯器錯誤(VS11): 「T」:模板參數不使用或抵扣部分特例

有人能告訴我爲什麼這不起作用?以及如何使其工作?

+0

爲什麼你想專注於不同容器的迭代器?專門用於迭代器的向量可能不會被使用,因爲它可能只是T *。你想看看在迭代器是否支持隨機訪問,在這種情況下,你想iterator_traits :: iterator_category – 2013-04-20 18:01:35

+0

@JohnBandela:我想花費迭代器類別,寫我自己的iterator_traits,並使它與STL容器兼容 – Frahm 2013-04-20 18:07:45

回答

2

您不能推斷嵌套::左側的類型。的確,你的問題沒有意義。考慮一下這個簡單的反例:

template <typename> struct Foo; 
template <> struct Foo<bool> { typedef float type; }; 
template <> struct Foo<char> { typedef float type; }; 

template <typename> struct DoesntWork; 

template <typename T> struct DoesntWork<typename Foo<T>::type> { }; 

現在如果我說DoesntWork<float>,應該T是什麼?

的一點是,沒有任何理由,任何T應該存在這Foo<T>::type是要匹配的事情,即使有一個,沒有理由爲什麼它會是唯一的。

+0

謝謝,它很明顯現在。 – Frahm 2013-04-20 17:48:58