1 year ago

#290186

test-img

user3059627

How to partially specialize a template by STL iterator template?

I want to specialize a template by STL iterator template like:

#include <list>

struct Tag0 {};
struct Tag1 {};

template<typename T>
struct get_tag {
    using tag = Tag0;
};

//Wanted by failed
template<typename T>
struct get_tag<typename std::list<T>::iterator> {
    using tag = Tag1;
};

//OK
template<typename T>
struct get_tag<std::list<T>> {
    using tag = Tag1;
};

I've read related topic Template Specialization for iterators of STL containers and got to know that it was a non-deducible context. How to solve this problem? Thank you.

c++

templates

partial-specialization

0 Answers

Your Answer

Accepted video resources