Let say i have two classes MyClass_one , MyClass_two
And i have function that accept only them as first parameter
template<typename T,typename ...Ts>
void doSomething(T one, Ts...two){}
Now to make it simple, if parameter one is MyClass_one it should print "im one" if its MyClass_two it should print "im two".
How to actually achieve this? The only solution i have came up with is really ugly and does not containt compile error throwing:
template<typename T> isOne{ static const bool value = false}
template<> isOne<MyClass_one>{ static const bool value = true}
template<typename T> isTwo{ static const bool value = false}
template<> isTwo<MyClass_two>{ static const bool value = true}
template<typename T, typename ... Ts>
void doSomething(T one, Ts...two){
if( isOne<T>::value ) { cout << "im one" << endl;}
else if ( isTwo<T>::value){ cout <<"im two" << endl;}
}
However how to implement the compiler error check without overloading (multiple definition of doSomething() function) e.g the function will not compile if something else than MyClass_one or MyClass_two is passed.
thanks for help.