STL vector implementation header size
Is there a requirement in C++ that
sizeof(std::vector<T>) == sizeof(std::vector<S>)
where S
and T
are arbitrary copy-assignable and copy-constructible types? For example, on my 64-bit Windows laptop with GCC
we have
sizeof(std::vector<int>) ==
sizeof(std::vector<std::tuple<std::vector<double>,
int, std::map<int, std::string> > >)
== 24
No, there is no requirement that the size of all std::vector
specializations be the same. The compiler is allowed to have different layouts and sizes for different specializations if it wants to.
In practice, one example is vector<bool>
which happens to give a different result in at least one instance:
std::cout << sizeof(std::vector<int>); // 24
std::cout << sizeof(std::vector<bool>); // 40