zoukankan      html  css  js  c++  java
  • boost之数据结构和容器

    1.静态数组array,boost对静态数组进行了封装,使用和普通数组一样的初始化式进行初始化。

    #include <iostream>
    #include <boost/array.hpp>
    using namespace std;
    using namespace boost;
    
    
    int main()
    {
    	array<int,10> ar;
    	ar.back() = 10;
    	array<string,3> ar1 = {"tiger","dog","cat"};
    	return 0;
    }
    

     2.dynamic_bitset可以自由扩充二进制位的位数,可以自由进行位操作,还有一堆方便操作判断的函数。

    #include <iostream>
    #include <boost/dynamic_bitset.hpp>
    using namespace std;
    using namespace boost;
    
    
    int main()
    {
    	dynamic_bitset<> db1;
    	dynamic_bitset<> db2(10);
    	cout << db2 <<endl;
    	db2.resize(6,true);
    	cout << db2 <<endl;
    	dynamic_bitset<> db3(string("100010"));
    	cout << db3<<endl;
    	cout << (db2 ^ db3) <<endl;
    	cout << (db2 & db3) <<endl;
    	if (db2.none())
    	{
    		cout << "have no 1"<<endl;
    	}
    	return 0;
    }
    

     3.unordered和hash_set,hash_map一样底层使用哈希表代替二叉树,实现关联容器。

    4.bimap双向map

    #include <iostream>
    #include <string>
    #include <boost/bimap.hpp>
    using namespace std;
    using namespace boost;
    
    
    int main()
    {
    	bimap<int,string> bm;
    	bm.left.insert(make_pair(1,"111"));
    	bm.left.insert(make_pair(2,"222"));
    	bm.right.insert(make_pair("string",3));
    	bm.right.insert(make_pair("bimap",4));
    	for (bimap<int,string>::right_iterator it = bm.right.begin();it != bm.right.end();++it)
    	{
    		cout << it->second <<endl;
    	}
    	
    	return 0;
    }
    

     5.any可以被初始化或者赋值任意类型的数据

    #include <iostream>
    #include <string>
    #include <boost/any.hpp>
    using namespace std;
    using namespace boost;
    
    
    int main()
    {
    	any a(100);
    	a =string("char *");
    	//a = vector<vector<>int >();
    	
    	return 0;
    }
    
  • 相关阅读:
    面向对象之prototype,__proto__
    Screen对象
    location对象
    history对象
    JS计时器
    window对象
    Dom操作html详细
    终端 git log 修改样式
    null 和 NULL 判断
    textfield设置左边距
  • 原文地址:https://www.cnblogs.com/liuweilinlin/p/3263770.html
Copyright © 2011-2022 走看看