while playing and trying to calculate total size of vector I tried something like
vector<double> vd;
auto area = vd.size()* sizeof (vd::value_type);
//Ive seen Stepanov use area as name for this kind of size, idk if he adds the sizeof vd also to area :)
Unfortunately this doesnt work...
I need to use vector<double>::value_type
but that makes code less readable.
Can it be made to work? I dont like sizeof vd.front()
because it just looks ugly to write front()
for this.
EDIT: decltype variants also fit in what I would call ugly category...
I think decltype
can be used:
auto area = vd.size() * sizeof(decltype(vd)::value_type);
as you are using auto
I assume C++11 is permitted.
Confirmed with g++ v4.7.2 and clang v3.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With