Created on 2009-10-24.00:00:00 last changed 171 months ago
Rationale:
The description in terms of push_back led some to believe that one could expect the exact same growth pattern from both resize and push_back (e.g.) which could lead to sub-optimal implementations. Additionally, [vector], p1 includes a statement that this container "supports (amortized) constant time insert and erase operations at the end;", therefore addressing the concern of this issue.
Proposed resolution:
In [vector.capacity]/10, change
void resize(size_type sz);Effects: If sz < size(), equivalent to erase(begin() + sz, end());. If size() < sz,
appends sz - size() default constructed elements to the sequenceequivalent to sz - size() consecutive evaluations of push_back(T()).
[ 2009-11-10 Howard adds: ]
Moved to Tentatively NAD after 5 positive votes on c++std-lib. Rationale added below.
If v is a vector, I think repeated calls to v.resize( v.size() + 1 ) should be amortized O(1), but it's not clear that's true from the text of the standard:
void resize(size_type sz);Effects: If sz < size(), equivalent to erase(begin() + sz, end());. If size() < sz, appends sz - size() default constructed elements to the sequence.
Seems to me if we used push_back instead of appends, we might be giving the guarantee I'd like. Thoughts?
History | |||
---|---|---|---|
Date | User | Action | Args |
2010-10-21 18:28:33 | admin | set | messages: + msg1299 |
2010-10-21 18:28:33 | admin | set | messages: + msg1298 |
2010-10-21 18:28:33 | admin | set | messages: + msg1297 |
2009-10-24 00:00:00 | admin | create |