There is no library implementation. I know that optimizes the layout for alignment. You can use such a program to check the tuple layout:
#include <iostream> #include <tuple> struct empty {}; int main() { using T = std::tuple<double, int, empty, short, long>; T t{}; std::cout << &t << '\n'; std::cout << &std::get<0>(t) << '\n'; std::cout << &std::get<1>(t) << '\n'; std::cout << &std::get<2>(t) << '\n'; std::cout << &std::get<3>(t) << '\n'; std::cout << &std::get<4>(t) << '\n'; std::cout << &t+1 << '\n'; std::cout << sizeof(T) << '\n'; }
libC ++ stores elements in the order of declaration and optimizes space for empty elements. Empty members are shunted in the direction of the front. Output Example:
0x7fff5ccf39f8 0x7fff5ccf39f8 0x7fff5ccf3a00 0x7fff5ccf39f8 0x7fff5ccf3a04 0x7fff5ccf3a08 0x7fff5ccf3a10 24
libstdC ++ stores elements in the reverse order of declarations and optimizes space for empty elements. Empty members are shunted in the direction of the front. Output Example:
0x7ffe4fc5b2a0 0x7ffe4fc5b2b0 0x7ffe4fc5b2ac 0x7ffe4fc5b2a0 0x7ffe4fc5b2a8 0x7ffe4fc5b2a0 0x7ffe4fc5b2b8 24
VS-2015 stores elements in the reverse order of declarations and does not optimize space for empty elements. Output Example:
0306FEF4 0306FF04 0306FF00 0306FEFC 0306FEF8 0306FEF4 0306FF0C 24
In this example, we see that optimizing the space for an empty element didnโt buy anything, since it is still suitable for the fill area.
There are no tools that automate the task of reducing fill in the standard.
source share