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
|
template<class A,class B, class C>
struct DoOp
{
typedef typename C::template apply<A,B>::type type;
};
template <int N>
struct int_
{
static const int value = N;
};
template<class A, class B>
struct plus
{
typedef int_< A::value + B::value> type;
};
struct plus_f
{
template<class T1,class T2>
struct apply
{
typedef typename plus<T1,T2>::type type;
};
};
template<class A, class B>
struct minus
{
typedef int_< A::value - B::value> type;
};
struct minus_f
{
template<class T1,class T2>
struct apply : minus<T1,T2>{}; //"forwarding" autre technique a priori meilleur
};
void main()
{
std::cout << DoOp< int_<9>, int_<1>, plus_f>::type::value << "\n";
std::cout << DoOp< int_<9>, int_<1>, minus_f>::type::value << "\n";
std::cin.ignore();
} |