Phlip said:
Herb Sutter recommends deque as the default container without a reason to
use another.
New questions:
Is deque more time efficient than vector? Is it more memory efficient than
list?
TC++PL 3 has a table of container comparison on page 464 (17.1.2).
From that table:
[] list front back Iterators
operations operations operations
vector const O(n)+ const+ Ran
deque const O(n) const const Ran
"In the iterators column, Ran means random-access iterator and Bi means
bidirectional iterator; the operations for a bidirectional operator are
a subset of those of a random-access iterator (19.2.1).
Other entries are measures of the efficiency of the operations. A const
entry means the operation takes an amount of time that does not depend
on the number of elements in the container. Another conventional
notation for constant time is O(1). An O(n) entry means the entry takes
time proportional to the number of elements involved. A + suffix
indicates that occasionally a significant extra cost is incurred. For
example, inserting an element into a list has a fixed cost (so it is
listed as const), whereas the same operation on a vector involves moving
the elements following the insertion point (so it is listed as O(n)).
Occasionally, all elements must be relocated (so I added a +).
The "big O" notation is conventional. I added the + for the benefit of
programmers who care about predictability in addition to average
performance. A conventional term for O(n)+ is amortized linear time.
Naturally, if a constant is large it can dwarf a small cost proportional
to the number of elements. However, for large data structures const
tends to mean "cheap", O(n) to mean "expensive", and O(log(n)) to mean
"fairly cheap". For even moderately large values of n, O(log(n)) is
closer to constant time than to O(n). People who care about cost must
take a closer look. In particular, they must understand what elements
are counted to get the n. No basic operation is "very expensive", that
is, O(n*n) or worse.
Except for string, the measures of costs listed here reflect
requirements in the standard. The string estimates are my assumptions.
These measures of complexity and cost are upper bounds. The measures
exist to give users some guidance as to what they can expect from
implementations. Naturally, implementers will try to do better in
important cases."