I am reading the book C++ primier, the tuple part. I had a problem when I finished a test program. Here's the code:
#include <tuple>
#include <iostream>
using namespace std;
tuple<int, bool, double> tuple1;
int main() {
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<i>
function didn't work as i
is non-const. How can I make
i
const? Or is there easier way to get the get<...>
function working?
Thank you @R Sahu for your answer and @Praetorian for linking to the duplicate question. Now I know that there's not an easy way to get over the problem.
But now I wonder why there isn't a easy way to do this in c++11?Thanks.