I am new to meta programming. I have looked at other questions that are similar but none of them do what I really want.
Here is my attempt at inversing a std::tuple. The main issue i have is inverting the data in the input tuple.
The logic to inverse the indices is not palatable and I could not proceed from this stage.
The code so far:
//===========================================================!
// type inversion of a tuple
template < typename Tuple, typename T >
struct tuple_push;
template < typename T, typename ... Args >
struct tuple_push<std::tuple<Args...>, T>
{
typedef std::tuple<Args..., T> type;
};
template < typename Tuple >
struct tuple_reverse;
template < typename T, typename ... Args >
struct tuple_reverse<std::tuple<T, Args...>>
{
typedef typename tuple_push<typename tuple_reverse<std::tuple<Args...>>::type, T>::type type;
};
template < >
struct tuple_reverse<std::tuple<>>
{
typedef std::tuple<> type;
};
//===========================================================!
template <typename First, typename ...Tails>
auto inverse(std::tuple<First, Tails...> & data)
-> decltype(tuple_reverse<std::tuple<First,Tails...>>::type)
{
using reverse_tup = tuple_reverse<std::tuple<First, Tails...>>::type;
static_assert(false, "Confused!")
return reverse_tup();
}
Looking forward to a compact and simple solution.
Aucun commentaire:
Enregistrer un commentaire