0

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.

  • Which information do you want from iterator? [`std::iterator_traits`](https://en.cppreference.com/w/cpp/iterator/iterator_traits) might help. – Jarod42 Mar 14 '22 at 18:53
  • 1
    [You can't obtain container type from its iterator type.](https://stackoverflow.com/a/3017518/5376789), so `T` cannot be deduced from `std::list::iterator`. – xskxzr Mar 15 '22 at 05:45
  • @Jarod42. No specific purpose, just some practices. Thank you for the advices. – user3059627 Mar 25 '22 at 11:39

0 Answers0