c++新特性

next,prev

求迭代器的前面和后面,范围[begin(),end()]

vector<int> a;
next(a.begin());
prev(a.end());

function

function<void(int,int)> f = [&](int u,int fa) {
    return f(1,1);
};

vector

vector x;
vector a(10,0);
vector b(10,vector<int>(10,0));
vector c(10,vector(10,vector<int>(10,0)));
vector d(10,vector(10,vector(10,vector<int>(10,0))));

auto

可以解析

vector<int> a;
for(int x:a);
for(auto x:a);//copy一份
for(auto& x:a);//加引用
vector<pair<int,int> a;
for(auto [x,y]:a);

arrary

数组,感觉可以当大号pair

vector<array<int,4>> e(10);
e[0]={1,2,3,4};
for(auto& [a,b,c,d]:e) {
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<'\n';
    a=rand(),b=rand(),c=rand(),d=rand();
}
for(auto [a,b,c,d]:e) {
    cout<<a<<" "<<b<<" "<<c<<" "<<d<<'\n';
}
posted @ 2022-07-31 13:15  ComplexPug  阅读(46)  评论(0编辑  收藏  举报