- 新增现代 C++ 教程的 Preface 章节,包括英文和中文版本 - 添加 C++ Primer 练习代码 - 新增 Learn C++ 教程的 C++ 开发简介章节 - 添加头文件解析文档 - 更新 mkdocs.yml,包含新教程的目录结构 - 修改项目设置,使用 Python 3.10环境
32 lines
729 B
C++
32 lines
729 B
C++
//
|
|
// structured.binding.cpp
|
|
//
|
|
// exercise solution - chapter 2
|
|
// modern cpp tutorial
|
|
//
|
|
// created by changkun at changkun.de
|
|
// https://github.com/changkun/modern-cpp-tutorial
|
|
//
|
|
|
|
#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;
|
|
} |