本文主要是介绍boost 容器tuple 信号signal2测试,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
// ConsoleApplication1.cpp : 此文件包含 "main" 函数。程序执行将在此处开始并结束。
//#include "pch.h"
#include"stdio.h"
#include<iostream>
#include<string>
using namespace std;#include<boost/unordered_map.hpp>
#include<boost/assign.hpp>
#include<boost/unordered_set.hpp>
#include<boost/tuple/tuple_comparison.hpp>
#include<boost/tuple/tuple_io.hpp>
#include<boost/tuple/tuple.hpp>
#include<boost/signals2.hpp>
#include<boost/thread.hpp>
#include<boost/shared_ptr.hpp>
#include<boost/make_shared.hpp>
#include<boost/bind.hpp>
#include<boost/date_time/posix_time/posix_time.hpp>
#include<thread>
using namespace boost::posix_time;
using namespace boost;
using namespace boost::assign;
boost::tuple<int, string, double> function()
{return boost::make_tuple(2, string("1344"), 4.4444);
}
void slots1(int a)
{cout << "....slot 1:" << a <<"id" << std::this_thread::get_id() << endl;
}
void slots2(int a)
{cout << "....slot 2:" << a <<"id" << std::this_thread::get_id() <<endl;
}
void run(boost::shared_ptr < signals2::signal<void(int)>> ptr)
{boost::this_thread::sleep(posix_time::seconds(5));cout << "wrork thread id" << std::this_thread::get_id() << endl;(*ptr)(1);
}
int main(int argc, char* argv[])
{ unordered_map<int, string> map = //主要是效率高于std::mapmap_list_of(1,"one")(2,"two")(3,"three");map.insert(make_pair(4, "three"));map.insert(make_pair(4, "three"));cout << map[1] << endl;cout << map.size() << endl;map.erase(2);cout << map.count(1) << endl;cout << "--------unordered_set------" << endl;unordered_set<int> set = (list_of(1), 2, 3, 4, 5);cout << "-------boost::tuple-------" << endl;typedef struct A{int a;double d;bool operator< (A &b) {return this->a < b.a;}}A;//tuple 可以存储最多10种不同类型的元素boost::tuple<int, string, double> tuple_1;tuple_1 = { 1,"one",1.1 };//数据获取cout << tuple_1.get<0>() << endl;cout << tuple_1.get<2>()<< endl;//使用比较必须包含#include<boost/tuple/tuple_comparison.hpp>boost::tuple<int, string, double> tuple_(1, "two", 2.8);assert(tuple_1 < tuple_);//使用比较必须包含#include<boost/tuple/tuple_io.hpp>cout << tuple_ <<tuple_1<<endl;//连接变量 boost::tie()int i;string str;boost::tie(i, str) = make_pair(1, string("12457654"));double d;tie(i, str, d) = boost::tuple<int,string,double>(boost::make_tuple(1, string("abc"), 3.333));cout<<"i=" << i << "str=" << str << endl;cout << "signals2" << endl;boost::shared_ptr< signals2::signal<void(int)> > sig= boost::make_shared<signals2::signal<void(int)>>();sig->connect(slots1);sig->connect(slots2);boost::thread work(boost::bind(run, sig));cout << "main thread id" << work.get_id() << endl;work.join();(*sig)(4);}
这篇关于boost 容器tuple 信号signal2测试的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!