To expand on G.Samaras's answer, you are allowed to do this:
typedef std::tuple<type0, type1, type2, type3, type4> MyTuple;
MyTuple myTuple;
type0 a = std::get<0>(myTuple);
type1 b = std::get<1>(myTuple); //...etc.
(edit: stupid me... as it turns out, you are also allowed to do this:
type0 a = std::get<type0>(myTuple);
type1 a = std::get<type1>(myTuple);
... leaving the rest of the answer in place as an example of how NOT to assume things)
So how do you associate 0 with type0 and so on? You do this (untested, but should work):
class MyTupleWrapper
{
private:
template <typename T> class TypeOffset {};
template <> class TypeOffset<type0> { enum { value = 0; } };
template <> class TypeOffset<type1> { enum { value = 1; } };
template <> class TypeOffset<type2> { enum { value = 2; } };
template <> class TypeOffset<type3> { enum { value = 3; } };
template <> class TypeOffset<type4> { enum { value = 4; } };
// ...etc
public:
typedef std::tuple<type0, type1, type2, type3, type4> MyTupleType;
explicit MyTupleWrapper(const MyTupleType& type) : _type(type) {}
template <typename T>
const T& Get() { return std::get< TypeOffset<typename T>::value >(_type); }
private:
MyTupleType _type;
}
To break this construct down without going too much into implementation, it is this:
a. You have two tools - the std::tuple<Type1, Type2, ...>
specialized type and the std::get<integer>(tupleObject);
to get specific types out of it. The integer param depends on the initial way you defined the tuple... so if your number is 3, the return value is the third type in your list of types inside that tuple (in our case, type3
)
b. The tuple itself supports normal assignment... so MyTupleType t; t = type1();
is allowed. But you can't invoke type1 a = t;
- it needs to be type1 a = std::get<1>(t);
which is stupid, because you can have many tuple types and you shouldn't need to remember which position you defined type1 in each tuple type.
c. What this wrapper does (intends to do?) is the ability to say type1 a = t.Get<type1>();
using template overloading to convert each type at compile time into its offset.