在玩和尝试计算向量的总大小时,我尝试了类似的东西
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 :)
Run Code Online (Sandbox Code Playgroud)
不幸的是,这不起作用......我需要使用,vector<double>::value_type但这会使代码的可读性降低.可以使它工作吗?我不喜欢sizeof vd.front()因为它写起来看起来很难看front().
编辑:decltype变体也适合我称之为丑陋的类别...