jeudi 1 mars 2018

How do I get index of elements in parameter pack

How do I get the following to put the index of the parameter pack element in the tuple?

template< typename... Ts >
class ClassA {
public:
    ClassA( Ts... ts ) : tup( make_tuple( ts, 0 )... ) {}
    // I would like it to expand to this.
    // ClassA( T0 ts0, T1 ts1 ) : tup( make_tuple( ts0, 0 ), make_tuple(ts1, 1) ) {}
    tuple<tuple<Ts, size_t>...> tup;
};

void main() {
    vector<int> a ={ 2, 4, 5 };
    list<double> b ={ 1.1, 2.2, 3.3 };
    ClassA<vector<int>, list<double>, vector<int>, list<double>> mm( a, b, a, b );
}

Thanks.

Aucun commentaire:

Enregistrer un commentaire