B
barcaroller
Does a list<T> keep track of its size or is the size re-calculated every
time you call list<T>.size()?
time you call list<T>.size()?
barcaroller said:Does a list<T> keep track of its size or is the size re-calculated every
time you call list<T>.size()?
barcaroller said:Does a list<T> keep track of its size or is the size re-calculated every
time you call list<T>.size()?
IIRC std::list::size() is *not* guaranteed to be constant-time, and in
most implementations it's indeed linear-time.
I think it has something to do with splice(), but I don't remember the
details.
Erik said:I think splice must run in O(n), where n is the number of spliced
elements, and that does not allow for recalculating the size when splicing.
Juha said:Don't you mean O(1)?
Don't you mean O(1)?
I was thinking of the version taking a position iterator, a list and two
iterators into this list. It is linear if the provided list is not
*this.
Problem is I can no longer remember the reason why this prevents
size() from being O(1).
Want to reply to this thread or ask your own question?
You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.