General template template specification

The template template specification looks like this:

template < template < class > class T > struct MyTemplate { }; 

How do I create a general (or partial) specialization for this template? Is it possible?

+7
c ++ generic-programming templates
source share
2 answers

Like this:

 #include <iostream> template <typename T> struct foo{}; template <typename T> struct bar{}; template < template < class > class T > struct MyTemplate { static const bool value = false; }; template <> struct MyTemplate<bar> { static const bool value = true; }; int main(void) { std::cout << std::boolalpha; std::cout << MyTemplate<foo>::value << std::endl; std::cout << MyTemplate<bar>::value << std::endl; } 
+5
source share

A specialization of this, for example, would be:

 template<> struct MyTemplate<std::auto_ptr> { // ... }; 
+3
source share

All Articles