
24 Apr
2007
24 Apr
'07
5:45 p.m.
Howard Hinnant wrote:
[snip]
I now prefer the semantics of clear(); swap();. This means that move assignment is O(N) instead of O(1). Ok Ion, take a deep breath and stay with me for just a minute longer. :-)
[snip]
First, for vector<type with trivial destructor>, clear() is O(1) in practice (or it should be). And clear() does not dump capacity, so the capacity gets reused via the swap. So we only have to worry about vector<type with non-trivial destructor>.
Right now I'm thinking about std::list and (unordered_)map/set. clear() does not sound very lightweight... ¿collateral damage? ;-) Regards, Ion