Does type order in std::tuple arguments have any effects?

c++, c++11, tuples

Solution

The standard doesn't place any restrictions on the actual layout of the types. The only things the order influences are the results of `std::get<N>`, `std::tuple_element<N, T>` and so on.

I know that libstdc++ and Visual C++ lay out the types in reverse order of the order given; libc++ lays out the types in the order given. This essentially means that there is no portable way to pick an order that always produces the best layout.

Other orders are possible, though. An implementation is allowed to implement tuple with a layout that always produces minimal size but still preserves the same semantics for `std::get<N>` and so on. I don't know of any standard library implementation that does this, though.

Problem

Say I want to store three types in a `tuple` : `int`, `float` and `std::vector<double>` If I leave aside matters of subsequent interface, does this ``` tuple<int, float, vector<int>> t; ``` have any differences from this ``` tuple<vector<int>, int, float> t; ``` Due to the implementation of `tuple` as a class of variadic bases, I'm expecting a different layout for the produced classes, but does it matter in any way ? Also are there any optimization considerations to take into account, when placing types in a `tuple` (eg put the largest first etc) ?

Original source