moorec's asdf dir #3

In this example, I appear to be playing around with template template parameters. Enjoy:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#include <iostream>
#include <list>

//
// template class wrapper
//
// accepts a template template parameter
// and a "contained" template parameter
//
template< template< typename AA > class A,
          typename B >
struct Wrapper
{
    A< B > a_;

    void operator()() const {
        std::cout << "normal" << std::endl;
    }
};
//
// partial specialization for Wrappers that
// "contain" int
//
template< template< typename AA > class A >
struct Wrapper< A, int >
{
    void operator()() const {
        std::cout << "special" << std::endl;
    }
};

// example class template for custom container
template< typename T > struct List { T t; };


int main()
{
    using namespace std;

    //Wrapper< List, double > f1;
    Wrapper< std::list, double > f1;
    f1(); // outputs normal

    Wrapper< List, int > f2;
    f2(); // outputs special

    return 0;
}
Topic archived. No new replies allowed.