Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon.

Pages: 1-

c++ parameter pack type selector

Name: Anonymous 2012-06-20 17:46

What I'm trying to achieve is, a class called TypeSelector that can be used like this:

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;
};

Name: Anonymous 2012-06-20 18:01

NIGGERS
























































NIGGERS












































































NIGGERS

































































NIGGERS

Name: Anonymous 2012-06-20 21:00

>>1
I have to ask... why? C++11 already has std::tuple which does what you want.

Name: Anonymous 2012-06-20 23:45

Do this:


template<unsigned int index>
using Get = typename std::conditional<(index == 0), Head, typename TypeSelector<Second, Tail...>::template Get<index-1> >::type;
};


the problem is there is ambiguity in a few places here. note the extra typename and template keywords.

this thread on SO ( http://stackoverflow.com/questions/610245/where-and-why-do-i-have-to-put-the-template-and-typename-keywords ) illustrates what needs to happen and why.

Name: Anonymous 2012-06-21 0:00

oh god what the fuck, sepples

Name: Anonymous 2012-06-21 0:52

lol Get = Head
Get Head

LOL!

Name: bampu pantsu 2012-06-26 2:55

bampu pantsu

Don't change these.
Name: Email:
Entire Thread Thread List