FYI template partial specialation emulation in MSVC6 now possible
In an attempt to invent a compiletime nested type sorter (still working on it) I discovered a wonderful way to emulate partial specialation without even having to change the syntax, by actually nest a class with the unspecified parameters :D Now this case only shows how you can specialize one parameter, similarily if you need to specialize any parameter you have to nest each and one of them into the other and then create a specialized nested class where the needed parameters are specialized accordingly. This is just the beginnig of an extensive use of compiletime type selection, and as already mentioned, i'm doing a recursive sort algoritm that will resolve the type order at compile time :D
PHP Code:
#include <iostream>
using namespace std;
template <int x>
struct Max_Partial{
template <class A,class B>
struct Max_Partial1{
typedef A Max_Partial2;
};
};
template <>
struct Max_Partial<0>{
template <class A,class B>
struct Max_Partial1{
typedef A Max_Partial2;
};
};
struct Max_Partial<1>{
template <class A,class B>
struct Max_Partial1{
typedef B Max_Partial2;
};
};
template <class A,class B,int x>
struct Max{
typedef Max_Partial<x>::Max_Partial1<A,B>::Max_Partial2 TMax;
};
struct A{
static const char* me(){return "class A";};
};
struct B{
static const char* me(){return "class B";};
};
void main(){
cout << Max<A,B,1>::TMax::me();
cout << Max<A,B,0>::TMax::me();
}