forked from changkun/modern-cpp-tutorial
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructured.binding.cpp
More file actions
22 lines (20 loc) · 545 Bytes
/
structured.binding.cpp
File metadata and controls
22 lines (20 loc) · 545 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#include <iostream>
#include <map>
#include <string>
#include <functional>
template <typename Key, typename Value, typename F>
void update(std::map<Key, Value>& m, F foo) {
for (auto&& [key, value] : m ) value = foo(key);
}
int main() {
std::map<std::string, long long int> m {
{"a", 1},
{"b", 2},
{"c", 3}
};
update(m, [](std::string key) -> long long int {
return std::hash<std::string>{}(key);
});
for (auto&& [key, value] : m)
std::cout << key << ":" << value << std::endl;
}