Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template template total specialization

A template template specification is like this:

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

How am I supposed to create a total (or partial) specialization for this template? Is this possible?

like image 599
scooterman Avatar asked Aug 13 '10 16:08

scooterman


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;
}
like image 152
GManNickG Avatar answered Sep 28 '22 10:09

GManNickG


A specialization of this would, for example, be:

template<>
struct MyTemplate<std::auto_ptr> {
   // ...
};
like image 37
sth Avatar answered Sep 28 '22 11:09

sth