讨论/综合讨论/Morden C++(11-17)/
Morden C++(11-17)

1.C++11

  1. 范围For循环
    范围For循环是C++11的新特性
C++98

for(vector<int>::itreator i = vec.begin(), i < vec.end(); i++)

C++11

for(int i : vec)
  1. Lambda演算
C++98
int cmp(int a, int b){
    return a < b;
}sort(vec.begin(), vec.end(), cmp);

C++11
sort(vec.begin(), vec.end(), [](int x, int y){return x < y;});

今天先写到这里,以后再更

展开讨论

C++11(2)

3.Auto

C++98
vector<int>::itreator it = vec.begin();

c++11
auto it = vec.begin()

4.constexpr
constexpr函数/变量
constexpr i = 123

C++17

1.结构化绑定

auto [i, j] = map[0];

for(auto [i, j] : map)//i = first, j = second
1