I'm interested in having tuples with "holes" in them. These holes are an empty struct. All holes will have the same type, called Empty
here.
For illustration purposes, let
struct DByte {
std::array<std::byte, 2> data;
};
struct Empty {
};
. As I expected,
sizeof(std::tuple<DByte, Empty, Empty>) = 2
. However,
sizeof(std::tuple<Empty, DByte, Empty>) = 3
sizeof(std::tuple<Empty, Empty, DByte>) = 3
and I can't understand why these last two types aren't of size 2 (on a platform with sizeof(std::byte) == 1 && alignof(std::byte) == 1
).
This demonstration also prints the memory layout of these types under Clang and GCC.
Why aren't all these tuples the same size with the following layout:
0 1 2
| DByte |
| Empty | Empty |
?