免费视频淫片aa毛片_日韩高清在线亚洲专区vr_日韩大片免费观看视频播放_亚洲欧美国产精品完整版

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費(fèi)電子書等14項(xiàng)超值服

開(kāi)通VIP
boost 學(xué)習(xí)筆記

先來(lái)看看如何賦值把:

#include <iostream>#include <vector>#include <string>#include<deque>#include <set>#include <map>#include <boost/assign.hpp>using namespace std;	int _tmain(int argc, _TCHAR* argv[]){		using namespace boost::assign;		//使用list_of	vector<int> v=list_of(1)(2)(3)(4)(5);	deque<string>d=(list_of("hello")("rollen"));	set<int>s=(list_of(10),20,30,40);	map<int, string>m=list_of(make_pair(1,"hello"))(make_pair(2,"rollen"));	//list_of可以全部使用括號(hào),也可以將括號(hào)和逗號(hào)一起使用,但是對(duì)于后者需要	// 將整個(gè)lits_of用括號(hào)括起來(lái)。否則編譯器無(wú)法推導(dǎo)出list_of的類型而無(wú)法賦值。	// 下面使用map_list_of 和pair_list_of		map<int,int>mp=map_list_of(1,1)(2,2)(3,3);	map<int,string>mp2=pair_list_of(1,"hello")(2,"rollen");	//其實(shí)還有tuple_list_of}

#include <iostream>#include <vector>#include <string>#include<deque>#include <set>#include <map>#include <multiset>#include <boost/assign.hpp>using namespace std;//減少重復(fù)輸入	int _tmain(int argc, _TCHAR* argv[]){		using namespace boost::assign;		vector<int>v=list_of(1).repeat(2,3)(4)(5);  //將3重復(fù)2次	//v=1,3,3,4,5	multiset<int>ms;	insert(ms).repeat_fun(5,&rand).repeat(2,1),10;	//ms=x,x,x,x,x,1,1,10	deque<int>d;	push_front(d).range(v.begin(),v.end()); //將一個(gè)序列的元素插入另外一個(gè)序列	//d=1,3,3,4,5}

與非標(biāo)準(zhǔn)容器一起使用

#include <iostream>#include <vector>#include <string>#include <stack>#include <queue>#include <boost/assign.hpp>using namespace std;//與非標(biāo)準(zhǔn)容器一起使用	int _tmain(int argc, _TCHAR* argv[]){		using namespace boost::assign;		stack<int>s=(list_of(1),2,3).to_adapter();	while(!s.empty()){		cout<<s.top()<<" ";		s.pop();	}	cout<<endl;	queue<string>q=(list_of("hello")("rollen").repeat(2,"holt")).to_adapter();	while(!q.empty()){		cout<<q.front()<<" ";		q.pop();	}	cout<<endl;	priority_queue<double>pq=(list_of(1.21)(2.23)).to_adapter();	while(!pq.empty()){		cout<<pq.top()<<" ";		pq.pop();	}	cout<<endl;}

 

assign也支持部分不在STL中定義的非標(biāo)準(zhǔn)容器,比如slist和hash_map  hash_set 用法和標(biāo)準(zhǔn)容器一樣、

此外,assign也支持大部分Boost的庫(kù)容器

 

#include <iostream>#include <vector>#include <string>#include <boost/assign.hpp>using namespace std;//list_of的嵌套使用// 構(gòu)建二維數(shù)組	int _tmain(int argc, _TCHAR* argv[]){		using namespace boost::assign;		vector<vector<int> >v=list_of(list_of(1)(2))(list_of(3)(4));	v+=list_of(5)(6),list_of(7)(8);	int a=1,b=2,c=3;	vector<int>v1=cref_list_of<3>(a)(b)(c);  //也可以使用ref_list_of	assert(v.size()==3);}

#include <boost/swap.hpp>using namespace std;//交換兩個(gè)數(shù)組,兩個(gè)數(shù)組的長(zhǎng)度必須一致	int _tmain(int argc, _TCHAR* argv[]){		int a1[10];	int a2[10];	std::fill_n(a1,10,1);	std::fill_n(a2,10,2);	boost::swap(a1,a2);}

特化 swap

#include <iostream>#include <vector>#include <string>#include <boost/swap.hpp>using namespace std;class point{public:	explicit point(int a,int b,int c):x(a),y(b),z(c){}	void print()const{		cout<<x<<" "<<y<<" "<<z<<endl;	}	void swap(point &p){		std::swap(x,p.x);		std::swap(y,p.y);		std::swap(z,p.z);		cout<<"inner swap"<<endl;	}private:	int x,y,z;};//特化std::swap  原則上不能動(dòng)stdnamespace std{	template<>	void swap(point &x,point &y){		x.swap(y);	}}	int _tmain(int argc, _TCHAR* argv[]){		point a(1,2,3);	point b(4,5,6);	cout<<"std swap"<<endl;	std::swap(a,b);	cout<<"boost swap"<<endl;	boost::swap(a,b);}

由于我們特化了swap,因此boost::swap 和std::swap效果一樣

特化ADL可找到的swap

#include <iostream>#include <vector>#include <string>#include <boost/swap.hpp>using namespace std;class point{public:	explicit point(int a,int b,int c):x(a),y(b),z(c){}	void print()const{		cout<<x<<" "<<y<<" "<<z<<endl;	}	void swap(point &p){		std::swap(x,p.x);		std::swap(y,p.y);		std::swap(z,p.z);		cout<<"inner swap"<<endl;	}private:	int x,y,z;};void swap(point &x,point &y){	x.swap(y);}	int _tmain(int argc, _TCHAR* argv[]){		point a(1,2,3);	point b(4,5,6);	cout<<"std swap"<<endl;	std::swap(a,b);	cout<<"boost swap"<<endl;	boost::swap(a,b);}

本站僅提供存儲(chǔ)服務(wù),所有內(nèi)容均由用戶發(fā)布,如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請(qǐng)點(diǎn)擊舉報(bào)。
打開(kāi)APP,閱讀全文并永久保存 查看更多類似文章
猜你喜歡
類似文章
vector 詳細(xì)用法 C++-CSDN博客
C++ 學(xué)習(xí)筆記1 - 日志 - 邱泳天 - 血與榮譽(yù)SNS平臺(tái) - Powered by ...
C與C++之異同
·C語(yǔ)言排序算法
C++對(duì)C語(yǔ)言的非面向?qū)ο筇匦詳U(kuò)充(3)
【C 】結(jié)構(gòu)體講解
更多類似文章 >>
生活服務(wù)
分享 收藏 導(dǎo)長(zhǎng)圖 關(guān)注 下載文章
綁定賬號(hào)成功
后續(xù)可登錄賬號(hào)暢享VIP特權(quán)!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服