Selecting a C 11 Standard Library Container: A Comprehensive Guide
Selecting an appropriate container in C 11 is crucial for efficient data management. Unlike the well-known "C Container choice" cheat sheet, a C 11 version is yet to be created.
However, creating such a chart can be simplified by adhering to two principles: prioritizing semantics and opting for the simplest solution when multiple options exist. Performance considerations should be addressed only when handling large datasets.
Associative vs. Simple Sequence
Containers are categorized into two primary types: associative and simple sequence.
Associative Containers
Use associative containers for:
Simple Sequence Containers
Use simple sequence containers when:
Step-by-Step Selection Process
For Associative Containers
Ordered?
Duplicates?
For Simple Sequence Containers
Memory stable?
Dynamically sized?
Double-ended?
Default Choice
In most cases, unless associative or specific requirements exist, std::vector is the preferred choice (as recommended by Sutter and Stroustrup).
The above is the detailed content of Which C 11 Standard Library Container Should I Choose?. For more information, please follow other related articles on the PHP Chinese website!