jeudi 3 août 2017

How to divide a tuple in C++

I have a question about dividing a tuple, as the title said.

In fact, I can do it using std::index_sequence, but the code looks ugly.

Is there an elegant way of accomplishing this?

Here are some code to show what I mean.

#include<tuple>
using namespace std;

template<typename THead, typename ...TTails>
void foo(tuple<THead, TTails...> tpl)
{
    tuple<THead> tpl_h { get<0>(tpl) };
    tuple<TTails...> tpl_t { /* an elegent way? */ }
    do_sth(tpl_h, tpl_t);
}

int main()
{
    foo(make_tuple(1, 2.0f, 'c'));
    return 0;
}

Aucun commentaire:

Enregistrer un commentaire