Namespaces
Variants
Views
Actions

Containers

From cppreference.com


Contents

[edit] Introduction

The standard library offers a wide range of containers which are used to store data. All these containers are implemented as templates to provide type-safety. Containers which provide an order of the data use the less comparison operator to compare two objects and determine their order.

The following containers are available:

  • array (C++11): Corresponds to C style array, but with container semantics.
  • dynarray (C++14): Corresponds to C style array, but with container semantics and dynamic allocation.
  • vector: Dynamically sized array.
  • stack: First-in last-out (FILO) data structure.
  • deque: First-in first-out (FIFO) queue.
  • list: Double-linked list, by default unsorted.
  • forward_list (C++11): Single-linked list.
  • set: Stores a sorted set of unique objects, where the key is (part of) the object.
  • multiset: Same as set<>, but allows non-unique keys.
  • map: Stores sorted unique key and value pairs.
  • multimap: Same as map<> but allows non-unique keys.
  • unordered_set (C++11): Stores a set of unique objects, where the (hash) key is (part of) the object.
  • unordered_multiset (C++11): Same as unordered_set<>, but allows non-unique keys.
  • unordered_map (C++11): Stores unique key and value pairs.
  • unordered_multimap (C++11): Same as unordered_map<>, but allows non-unique keys.

As a rule of thumb, start with a vector<> to store your data, if you are not sure which type of container you should use.


[edit] array

[edit] dynarray

[edit] vector

[edit] stack

[edit] deque

[edit] list

[edit] forward_list

[edit] set

[edit] multiset

[edit] map

[edit] multimap

[edit] unordered_set

[edit] unordered_multiset

[edit] unordered_map

[edit] unordered_multimap