а можно через Loki::Typelist
#include "Loki/HierarchyGenerators.h"
enum some_enum { en1, en2, en3 };
template <some_enum>
void foo()
{
std::cout << "unspecified" << std::endl;
}
template <>
void foo<en1>()
{
std::cout << "en1 implementation" << std::endl;
}
template <class Enum, Enum Value>
struct Enum2Type
{
typedef Enum type;
};
template <class ResultType>
struct helper
{
template <class T, class B>
class unit;
template <class Enum, Enum SE, class B>
class unit<Enum2Type<Enum, SE>, B> : public B
{
protected:
static ResultType unit_call(some_enum se)
{
if (se == SE) return foo<SE>();
return B::unit_call(se);
}
};
template <class Enum, Enum SE>
class unit<Enum2Type<Enum, SE>, Loki::EmptyType>
{
protected:
static ResultType unit_call(some_enum se)
{
return foo<SE>();
}
};
};
struct cfoo : Loki::GenLinearHierarchy
<
Loki::TL::MakeTypelist
<
Enum2Type<some_enum, en1>,
Enum2Type<some_enum, en2>,
Enum2Type<some_enum, en3>
>::Result,
helper<void>::unit
>
{
static void call(some_enum se)
{
return unit_call(se);
}
};
int _tmain()
{
/*foo<en1>();
foo<en2>();*/
cfoo::call(en1); // забыл убрать namespace
cfoo::call(en2);
return 0;
}