if/switch 变量声明强化
void defineVarInIfOrSwithc() {
// 在if,switch中直接定义变量
vector<int> vec{1, 2, 3, 4, 5};
if (auto iter = std::find(vec.cbegin(), vec.cend(), 4);iter != vec.cend()) {
cout << *iter << endl;
}
if (auto iter = std::find(vec.begin(), vec.end(), 4);iter != vec.end()) {
*iter *= 10;
}
}
结构化绑定
结构化绑定对写代码的便利性提升了很多
std::tuple<string, int, double> foo() {
return std::make_tuple("hello world", 2, 3.14);
}
void structuredBind() {
// 结构化绑定
vector<std::pair<string, int>> strIntVec{
{"hello", 1},
{"world", 2},
{"hello", 3},