-
-
Notifications
You must be signed in to change notification settings - Fork 3.1k
Expand file tree
/
Copy path11.7.flat.map.cpp
More file actions
23 lines (21 loc) 路 636 Bytes
/
Copy path11.7.flat.map.cpp
File metadata and controls
23 lines (21 loc) 路 636 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
//
// 11.7.flat.map.cpp
// chapter 11 cpp23
// modern c++ tutorial
//
// created by changkun at changkun.de
// https://github.com/changkun/modern-cpp-tutorial
//
#include <flat_map>
#include <iostream>
// std::flat_map is an associative container backed by sorted contiguous
// storage (by default two vectors). It trades slower insertion for fast
// lookup and cache-friendly iteration.
int main() {
std::flat_map<int, const char*> m;
m.insert({3, "three"});
m.insert({1, "one"});
m.insert({2, "two"});
for (const auto& [k, v] : m) // iterated in sorted key order
std::cout << k << " => " << v << '\n';
}