C++11 STL

六大部件

  • 容器
  • 分配器
  • 算法
  • 迭代器
  • 适配器
  • 仿函数

image

# include <iostream>
# include <vector>
# include <algorithm>
# include <functional>
using namespace std;

int main()
{
    int ia[6] = { 27,210,12,47,109,83 };
    vector<int, allocator<int>> vi(ia, ia + 6);
    //********容器  vector   分配器   allocator********
    //vector  4种初始化
    //std::vector<int> first;                                // empty vector of ints
    //std::vector<int> second(4, 100);                       // four ints with value 100
    //std::vector<int> third(second.begin(), second.end());  // iterating through second
    //std::vector<int> fourth(third);                       // a copy of third
    cout << count_if(vi.begin(), vi.end(), not1(bind2nd(less<int>(), 40))) << endl;
    //算法  count_if  迭代器  vi.begin()  仿函数 less  适配器 not1 bind2nd
    return 0;
}

容器

  1. 序列容器
  • array
  • vector
  • deque
  • list : 双向链表
  • forward_list:单链表
  1. 排序容器
  • set/multiset :红黑树
  • map/multimap : 红黑树
  1. 哈希容器
  • unordered_set/unordered_multiset
  • unordered_map/unordered_multimap

评论

暂无评论