Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7994611
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:11:02+00:00 2026-06-04T14:11:02+00:00

There’s a well known image (cheat sheet) called C++ Container choice. It’s a flow

  • 0

There’s a well known image (cheat sheet) called “C++ Container choice”. It’s a flow chart to choose the best container for the wanted usage.

Does anybody know if there’s already a C++11 version of it?

This is the previous one:
eC++ Container choice

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T14:11:03+00:00Added an answer on June 4, 2026 at 2:11 pm

    Not that I know of, however it can be done textually I guess. Also, the chart is slightly off, because list is not such a good container in general, and neither is forward_list. Both lists are very specialized containers for niche applications.

    To build such a chart, you just need two simple guidelines:

    • Choose for semantics first
    • When several choices are available, go for the simplest

    Worrying about performance is usually useless at first. The big O considerations only really kick in when you start handling a few thousands (or more) of items.

    There are two big categories of containers:

    • Associative containers: they have a find operation
    • Simple Sequence containers

    and then you can build several adapters on top of them: stack, queue, priority_queue. I will leave the adapters out here, they are sufficiently specialized to be recognizable.


    Question 1: Associative ?

    • If you need to easily search by one key, then you need an associative container
    • If you need to have the elements sorted, then you need an ordered associative container
    • Otherwise, jump to the question 2.

    Question 1.1: Ordered ?

    • If you do not need a specific order, use an unordered_ container, otherwise use its traditional ordered counterpart.

    Question 1.2: Separate Key ?

    • If the key is separate from the value, use a map, otherwise use a set

    Question 1.3: Duplicates ?

    • If you want to keep duplicates, use a multi, otherwise do not.

    Example:

    Suppose that I have several persons with a unique ID associated to them, and I would like to retrieve a person data from its ID as simply as possible.

    1. I want a find function, thus an associative container

    1.1. I couldn’t care less about order, thus an unordered_ container

    1.2. My key (ID) is separate from the value it is associated with, thus a map

    1.3. The ID is unique, thus no duplicate should creep in.

    The final answer is: std::unordered_map<ID, PersonData>.


    Question 2: Memory stable ?

    • If the elements should be stable in memory (ie, they should not move around when the container itself is modified), then use some list
    • Otherwise, jump to question 3.

    Question 2.1: Which ?

    • Settle for a list; a forward_list is only useful for lesser memory footprint.

    Question 3: Dynamically sized ?

    • If the container has a known size (at compilation time), and this size will not be altered during the course of the program, and the elements are default constructible or you can provide a full initialization list (using the { ... } syntax), then use an array. It replaces the traditional C-array, but with convenient functions.
    • Otherwise, jump to question 4.

    Question 4: Double-ended ?

    • If you wish to be able to remove items from both the front and back, then use a deque, otherwise use a vector.

    You will note that, by default, unless you need an associative container, your choice will be a vector. It turns out it is also Sutter and Stroustrup’s recommendation.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are many conflicting statements around. What is the best way to get the
There is a website called Gild.com that has different coding puzzles/challenges for users to
There doesn't seem to be any tried and true set of best practices to
There is a known issue with using jquery fadeOut, fadeIn, and fadeToggle, when fading
There are two layers (Image control with PNG bitmap) inside Grid (or Canvas): one
There is a method in the Messages class called questionWhatisYourName() this method is called
There seem to be very different opinions about using transactions for reading from a
There seems to be a similar question to this on here but with the
There are load balanced tomcat web servers. Every request could be served by different
There seems to be too many attributes/parameters in CSS... I want to know all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.