1

In the "lighting tour" of Stroustrup's 4th edition of TC++PL, he says:

I recommend the standard-library vector as the default type for sequences of elements: you need a reason to choose another.

It's clear why one would choose a set over a vector based on the invariant of a set.

But what about list and deque? Unfortunately I don't have enough knowledge/experience to know when to use those over a vector.

Rather than going down a rabbit hole re-searching linked-lists and deque's; which I am going to do when I reach the later chapters. I was hoping someone can give a brief conceptual outline of when there's a reason to use linked-list or a deque over a vector?

Sam Hammamy
  • 10,819
  • 10
  • 56
  • 94
  • 1
    Different collections have different time complexities when performing operations like insertion, deletion, in the middle, at the beginning or end, etc. – Steve Nov 11 '17 at 18:58
  • Does that mean there's then specific use cases for each one? What would be a use case for fastest insertion? fastest deletion? – Sam Hammamy Nov 11 '17 at 19:03
  • 1
    Read [here](https://baptiste-wicht.com/posts/2012/12/cpp-benchmark-vector-list-deque.html) and also do your own tests – Kjell Gunnar Nov 11 '17 at 19:05
  • 3
    @SamHammamy Linked lists also have pointer stability for data in case of reorganizations. – user0042 Nov 11 '17 at 19:05
  • 1
    This is answered by the "When to NOT use std::vector" answer in the duplicate question. – Sam Varshavchik Nov 11 '17 at 19:10
  • @SamVarshavchik Thanks! That answer is perfect. I am going to keep this question around in case it comes up in future searches. – Sam Hammamy Nov 11 '17 at 19:13

0 Answers0