What is the difference between sequence containers and container adaptors in c++?
Here i mean sequence containers as vectors, deque, list while container adaptors as stack, queue, priority_queue.
When do we prefer sequence containers and container adaptors?
Sequence containers
You could see sequence container as containers “built from scratch”. They use different structures to hold data and have different algorithmic time to insert, delete and retreive element.
You can find a lot of information about the algorithmic time of containers here
Container adapters
Container adapters are behavior added over sequence containers making them respect different paradigms. The added behavior can be a stricter behavior (the stack will only allow you to pop/push item on it, no random insert). They are other type of containers that did not need a new storing behavior then those already existing. As an example, a stack could be built over a vector. It would then uses the data structure of vector, but restrain the usage to a certain set of functions to mimic a stack.
Most important over all this is to make sure that you use the right container to suit your needs. A stricter container will help you prevent missuses of your datum and knowing the usage of your data will help you chose the good container to get the best performances.
More information about container adapters can be found here
What should I use most of the time?
Many experts (Scott Meyer, Bjarne Stroustrup) suggest the use of the
vectorby default while others (like Herb Sutter as Steve Jessop pointed out) suggest thedeque. I would strongly suggest you to chose the container that best suits your need.