Namespaces
Variants
Actions

Containers

From cppreference.com
Revision as of 03:42, 25 October 2013 by Gemini67 (Talk | contribs)

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)


Contents

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.


array

dynarray

vector

stack

deque

list

forward_list

set

multiset

map

multimap

unordered_set

unordered_multiset

unordered_map

unordered_multimap