#include
#include
#include
#include
using namespace std;
int main()
{
int i[6] = {1,2,3,4,5,6};
vector<int,allocator<int>> vec (i,i+6);
for (auto& elem : vec){
std::cout << elem << " ";
}
cout <<endl;
// 相当于x<6是否成立,用于判定那些小于6的元素
cout<< "there are " << count_if(vec.begin(),vec.end(),
bind2nd(less<int>(), 6)) << " elements that are less than 6" <<endl;
// 相当于3
cout << "there are " << count_if(vec.begin(),vec.end(),
bind1st(less<int>(), 3)) << " elements that are not less than 3" << endl;
return 0;
}
容器的基础
容器中的元素在 [ c.begin(), c.end()) 之间,当迭代器遍历到 c.end()时候,实际已经脱离了容器的元素区间。
基本遍历
使用for 循环进行遍历
std::vector<double> vec;
for (auto& elem : vec){
std::cout << elem << std::endl;
}
定义
所谓的仿函数(functor),是通过重载()运算符模拟函数形为的类。因此,这里需要明确两点:
STL算法特征