
On Friday 27 March 2009 20:02:41 Satyam Shekhar wrote:
b. Why isn't the reserve function already there in a deque? Assuming there is a [use] valid case for this function, adding it shouldn't be too difficult. Allocate a block(s) and add the address to the top-level array.
I'm pretty sure the assumption "there is a valid [use] case" is false. reserve() is in vector so that clients can control when a possible complete realloc+move is going to happen, and possibly even avoid it altogether. This is important for a lot of reasons, including that all iterators get invalidated. For deque, new blocks are simply allocated as needed and the existing blocks are never reallocated. Thus, there would be little point with preallocating the array. -- kind regards, Esben