Hi, I have an enum in my program named Stype like below
Code:
enum Stype { T1, T2, T3 };
There is a template function compute which take two Stype as
template parameter
Code:
template< Stype st1, Stype st2 >
void compute(){
COMPILE_TIME_ASSERT(st1<=st2);
// do something
}
compute is symmetric so that compute<T1,T2>() == compute<T2,T1>()
but I want to restrict user to be able to call compute onnly when st1<=st2 as
forced by a compile-time assert in code.

Now, there is a function compute_at_runtime which is passed two Stype t1, t2 and calls the
correct compute function based on types of t1&t2. currently I have implemented it by hand like below
Code:
void compute_at_runtime( Stype t1, Stype t2 )
{
	if( t1==T1 ){
		if( t2==T1 ){
			compute<T1,T1>();
		} else
		if( t2==T2 ){
			compute<T1,T2>();
		} else
		if( t2==T3 ){
			compute<T1,T3>();
		}
	} else
	if ( t1==T2 ){
		if ( t2==T2 ){
			compute<T2,T2>();
		} else
		if ( t2==T3 ){
			compute<T2,T3>();
		}
	} else
	if ( t1==T3 ){
		if ( t2==T3 ){
			compute<T3,T3>();
		}
	}
}
but I want to make it a metaprogram which generates the code automatically by
recursive template instanciating (like Factorial<N> example) because the user
must be able to extend Stype with new types ( e.g. T4,T5,... ) and it becomes
vary cumbersome to take care of this function

I have written some simple metaprograms, but this one is very hard for me.
I would be very appreciated if anyone could help me with this
Many Thanks