mercredi 3 juin 2015

How can I add const to get<>(t) function of tuple in C++ 11?

I am reading the book C++ primier,the tuple part.

I had a problem when I did a test program,here's the code.

tuple<int, bool, double> tuple1;
tuple1 = make_tuple<int, bool, double>(1,true,3.3);

for (int  i = 0; i <tuple_size<decltype(tuple1)>::value; i++)
{
    cout << get<i>(tuple1) << endl;
}

But the get function didn't work as i is non-const.How can I make the i const.

Or are there easier way to do so?Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire