Re: tuples in C++11
Single Stage to Orbit=E6=96=BC 2012=E5=B9=B48=E6=9C=8815=E6=97=A5=E6=98=9F=
=E6=9C=9F=E4=B8=89UTC+8=E4=B8=8A=E5=8D=882=E6=99=8217=E5=88=8626=E7=A7'=
=E5=AF=AB=E9=81=93=EF=BC=9A
Hello!
Suppose I have the following:
int main()
{
typedef boost::tuple<int, int, int> tuple3;
std::vector<tuple3> tuples;
tuples.push_back(tuple3(1, 2, 3));
tuples.push_back(tuple3(7, 8, 9));
tuples.push_back(tuple3(4, 5, 6));
for (auto& i : tuples)
std::cout << i.get<0>() << " " << i.get<1>() << " " <<
i.get<2>() << '\n';
return 0;
}
Is it even possible to have something like this:
for (auto& i : tuples)
{
for (unsigned j = 0; j < 3; ++j)
{
std::cout << i.get<j>();
if (j < 3)
std::cout << " ";
}
std::cout << '\n';
}
When I try it, GCC 4.6.3 says it's illegal to have an non constant
expression as in 'i.get<j>'. Are there any workarounds for this one?
Thanks!
--
Tactical Nuclear Kittens
Single Stage to Orbit=E6=96=BC 2012=E5=B9=B48=E6=9C=8815=E6=97=A5=E6=98=9F=
=E6=9C=9F=E4=B8=89UTC+8=E4=B8=8A=E5=8D=882=E6=99=8217=E5=88=8626=E7=A7'=
=E5=AF=AB=E9=81=93=EF=BC=9A
Hello!
Suppose I have the following:
int main()
{
typedef boost::tuple<int, int, int> tuple3;
std::vector<tuple3> tuples;
tuples.push_back(tuple3(1, 2, 3));
tuples.push_back(tuple3(7, 8, 9));
tuples.push_back(tuple3(4, 5, 6));
for (auto& i : tuples)
std::cout << i.get<0>() << " " << i.get<1>() << " " <<
i.get<2>() << '\n';
return 0;
}
Is it even possible to have something like this:
for (auto& i : tuples)
{
for (unsigned j = 0; j < 3; ++j)
{
std::cout << i.get<j>();
if (j < 3)
std::cout << " ";
}
std::cout << '\n';
}
When I try it, GCC 4.6.3 says it's illegal to have an non constant
expression as in 'i.get<j>'. Are there any workarounds for this one?
Thanks!
--
Tactical Nuclear Kittens
Do you plan to compress imutable objects into a serializable frozen file in=
the hard disk or your own heap manager?
If you are not planning to do that then I don't think immutable tuples
are very helpful.