partial specialization for iterator type of a specified container type

别来无恙 提交于 2019-12-21 20:13:27

问题


I have a template struct, which accepts a Iterator type for the template argument. now I need to specialize that class for iterators of different containers. I have tried with std::vector

template<typename Iterator>
struct AC {

};

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

};

but I got this compiler error(VS11): 'T' : template parameter not used or deducible in partial specialization

Can someone please tell me why this doesn't work? And how to make it work?


回答1:


You can't deduce types left of a nesting ::. Indeed, your question makes no sense. Consider this simpler counter-example:

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> { };

Now if I say DoesntWork<float>, what should T be?

The point is that there is no reason that any T should exist for which Foo<T>::type is a thing you want to match, and even if there were one, there's no reason why it would be unique.



来源:https://stackoverflow.com/questions/16123279/partial-specialization-for-iterator-type-of-a-specified-container-type

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!