Question

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?

Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top