I have a tuple type. I want to add a element type in it to get a new tuple type. I can do it like
decltype tuple_cat(MyTuple, std::tuple())
C++14 offers a library to generate a sequence of integers at compile type. This helps manipulating static sequences like tuples and arrays (example). An integer sequence can be obtained
template
struct integer_sequence {};
template
struct implementation : implementation {};
template
struct implementation<0, Ints...>
{
typedef integer_sequence type;
};
template
using index_sequence_for = typename implementation::type;
To concat MyTuple
and MyType
you can write the simple functions:
template
auto concat(X x, Tuple t, integer_sequence)
-> decltype( std::make_tuple(x, std::get(t)...) )
{
return std::make_tuple(x, std::get(t)...);
}
template
std::tuple concat(X x, std::tuple t)
{
return concat(x, t, index_sequence_for());
}
concat(MyType, MyTuple);