Name: Anonymous 2012-06-20 17:46
What I'm trying to achieve is, a class called TypeSelector that can be used like this:
and the type of x will be the nth class.
So /prog/, what the fuck is wrong with this code?
My compiler says that
TypeSelector<class1, class2, class3>::Get<n> x;and the type of x will be the nth class.
So /prog/, what the fuck is wrong with this code?
My compiler says that
TypeSelector<Second, Tail...>::Get<index-1> is a value and not a type, no idea why.
#include <type_traits>
template <typename... List>
class TypeSelector;
template<typename Head>
class TypeSelector<Head>
{
public:
template<unsigned int index>
using Get = Head;
};
template<typename Head, typename Second, typename... Tail>
class TypeSelector<Head, Second, Tail...>
{
public:
template<unsigned int index>
using Get = std::conditional<(index == 0), Head, TypeSelector<Second, Tail...>::Get<index-1> >::type;
};