• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1# <small>nlohmann::</small>ordered_map
2
3```cpp
4template<class Key, class T, class IgnoredLess = std::less<Key>,
5         class Allocator = std::allocator<std::pair<const Key, T>>>
6struct ordered_map : std::vector<std::pair<const Key, T>, Allocator>;
7```
8
9A minimal map-like container that preserves insertion order for use within [`nlohmann::ordered_json`](ordered_json.md)
10(`nlohmann::basic_json<ordered_map>`).
11
12## Template parameters
13
14`Key`
15:   key type
16
17`T`
18:   mapped type
19
20`IgnoredLess`
21:   comparison function (ignored and only added to ensure compatibility with `#!cpp std::map`)
22
23`Allocator`
24:   allocator type
25
26## Member types
27
28- **key_type** - key type (`Key`)
29- **mapped_type** - mapped type (`T`)
30- **Container** - base container type (`#!cpp std::vector<std::pair<const Key, T>, Allocator>`)
31- **iterator**
32- **const_iterator**
33- **size_type**
34- **value_type**
35- **key_compare** - key comparison function
36```cpp
37std::equal_to<Key>  // until C++14
38
39std::equal_to<>     // since C++14
40```
41
42## Member functions
43
44- (constructor)
45- (destructor)
46- **emplace**
47- **operator\[\]**
48- **at**
49- **erase**
50- **count**
51- **find**
52- **insert**
53
54## Examples
55
56??? example
57
58    The example shows the different behavior of `std::map` and `nlohmann::ordered_map`.
59
60    ```cpp
61    --8<-- "examples/ordered_map.cpp"
62    ```
63
64    Output:
65
66    ```json
67    --8<-- "examples/ordered_map.output"
68    ```
69
70## See also
71
72- [ordered_json](ordered_json.md)
73
74## Version history
75
76- Added in version 3.9.0 to implement [`nlohmann::ordered_json`](ordered_json.md).
77- Added **key_compare** member in version 3.11.0.
78