How can one determine the runtime size of an object ?
We're not talking about the size of the type but the actual size of an object that can vary during the execution, eg :
vector<int> v;
auto a = MagicSizeF(v); // magic size function
v.push_back(2);
v.push_back(2);
// this should hold - ok there's small consainer optimizations and initial
// vector capacity and implementation details, but you get what I mean
assert(MagicSizeF(v) > a);
In the vector case it could be implemented like this :
template<typename T>
auto MagicSizeF(vector<T> const& v) {
return v.size()*sizeof(T); // or v.capacity() to be strict
// other implementation details memory consumers could be added
}
but is there a Standard / generic way to do this for objects of arbitrary type ? Is an ABI needed to bypass all the implementation details ?