Здравствуйте, pilot.net, Вы писали:
Засунь все в шаблонного уродца типа
struct FunctionHolder
{
template<typename T>
void operator()(T)
{
throw std::exception();
}
};
template<>
void FunctionHolder::operator()<float>(float f)
{
std::cout << "i am float" << std::endl;
}
template<>
void FunctionHolder::operator()<double>(double d)
{
std::cout << "i am double" << std::endl;
}
enum Types
{
zeroType,
floatType,
doubleType
};
template<Types t>
struct Caller
{
;
};
template<>
struct Caller<zeroType>
{
template<typename Callee, typename ... Params>
static void call(Types t, Callee callee, Params... params)
{
throw std::exception();
}
};
template<>
struct Caller<floatType>: Caller<zeroType>
{
template<typename Callee, typename ... Params>
static void call(Types t, Callee callee, Params... params)
{
if(t == floatType)
callee(params...);
else
Caller<zeroType>::call(t, callee, params...);
}
};
template<>
struct Caller<doubleType>: Caller<floatType>
{
template<typename Callee, typename ... Params>
static void call(Types t, Callee callee, Params... params)
{
if(t == doubleType)
callee(params...);
else
Caller<floatType>::call(t, callee, params...);
}
};
struct CallerFinal:Caller<doubleType>
{
template<typename Callee, typename ... Params>
static void call(Types t, Callee callee, Params... params)
{
Caller<doubleType>::call(t, callee, params...);
}
};
int main(int argc, wchar_t** argv)
{
CallerFinal::call(floatType,FunctionHolder(), 1.0f);
CallerFinal::call(doubleType,FunctionHolder(), 1.0);
}