上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 24 下一页
摘要: 1.boost里的thread创建之后会立即启动。代码示例:#include #include #include #include #include using namespace std;using namespace boost;mutex io_mu;void printing(int& x,const string str){ for (int i = 0;i #include #include #include #include using namespace std;using namespace boost;mutex io_mu;void printing(int&am 阅读全文
posted @ 2013-08-13 22:54 l851654152 阅读(2212) 评论(0) 推荐(0) 编辑
摘要: 七夕节快乐!人应该有梦想! 阅读全文
posted @ 2013-08-13 21:55 l851654152 阅读(152) 评论(0) 推荐(0) 编辑
摘要: 1.boost里的互斥量类型由mutex表示。代码示例:#include #include #include #include #include using namespace std;using namespace boost;int main(){ mutex mu; try { this_thread::sleep(posix_time::seconds(2)); mu.lock();//锁定cout对象 cout #include #include #include #include using namespace std;using namespace boost;templa... 阅读全文
posted @ 2013-08-13 19:12 l851654152 阅读(16914) 评论(0) 推荐(0) 编辑
摘要: boost里的bind,function,signal三个组件都是对用函数做参数(其他算法也用函数做参数),对函数的某一项进行操作。bind主要是对函数参数的作用。function主要是对函数地址的封装。signal主要是异步回调。用函数做参数时1.普通函数需要传递函数地址。2.函数对象需要传递一个对象3.成员函数需要传递对象,指明所调用的成员函数。如果只有对象则符合规则2. 阅读全文
posted @ 2013-08-13 18:48 l851654152 阅读(576) 评论(0) 推荐(0) 编辑
摘要: boost里的signal是一个模板类,不区分信号种类,产生信号统一用()调用操作符。1.回调普通函数代码示例:#include #include #include #include using namespace std;using namespace boost::signals2;void slots1(){ cout sig; sig.connect(&slots1); sig.connect(&slots2); sig(); return 0;}2.使用组号和注册位置代码示例,可以使用有名对象,传递的是函数对象。#include #include #include # 阅读全文
posted @ 2013-08-13 18:41 l851654152 阅读(401) 评论(0) 推荐(0) 编辑
摘要: boost中function是对函数指针和函数对象的进行封装的模板类。定义示例:function func生成一个空的对象,表示函数参数个数为零,返回类型为int。#include #include #include #include using namespace std;using namespace boost;int f(int a,int b){ return a + b;}int main(){ function fun;//定义一个空的function对象 fun = f;//调用赋值操作符 if (fun) { cout << fun(10,20) << 阅读全文
posted @ 2013-08-13 14:57 l851654152 阅读(214) 评论(0) 推荐(0) 编辑
摘要: bind1st bind2nd在stl里面有具体的实现,只是只能绑定两个参数。boost里面的bind使用bind(Fun f,A1 a1,A2,a2...)产生一个对象,这个对象可以有占位符,可以等到调用函数对象的时候传递参数进去即通过bind b(..);b(args);bind绑定参数是通过存储值的形式,如果对象很大,需要耗费很大的代价,可以用ref,但是bind是延后处理的,需要保证所引用的对象在调用之前不被释放。一.绑定普通函数#include #include #include using namespace std;using namespace boost;int f(int 阅读全文
posted @ 2013-08-13 00:44 l851654152 阅读(362) 评论(0) 推荐(0) 编辑
摘要: #ifndef POW3_H#define POW3_Htemplate class Pow3{public: enum{result = 3 * Pow3::result};};templateclass Pow3{public: enum{result = 1};};#endif此代码计算三的N次方。#ifndef POW3_H#define POW3_Htemplate class Sqrt{public: enum{mid = (LO + HI + 1)/2}; enum{result = (N ::result:Sqrt::result};};templateclass Sqrt{p 阅读全文
posted @ 2013-08-12 22:37 l851654152 阅读(231) 评论(0) 推荐(0) 编辑
摘要: 一.循环控制1.for循环1.1 for...in 语句for var in list;//list可以是变量以空格分隔,可以是变量列表docmd;//可以是一组命令done;示例代码:#!/bin/bashfor i in root group user;do echo $idone;1.2 c语言风格的循环控制for((赋值;判断;运算));示例代码#!/bin/bashfor((i=1;i<=10;i++));do echo $idone;2.while循环while condition//其中condition可以为truedocommands;done示例代码#!/bin/ba 阅读全文
posted @ 2013-08-07 10:33 l851654152 阅读(297) 评论(0) 推荐(0) 编辑
摘要: 1 #!/bin/bash 2 line="root:x:0:0:root:/root:bin/bash" 3 oldIFS=$IFS 4 IFS=":" 5 count=0 6 for item in $line; 7 do 8 [ $count -eq 0 ] && user=$item; 9 [ $count -eq 6 ] && shell=$item; 10 let count++ 11 done; 12 IFS=$oldIFS 13 echo $user\'s... 阅读全文
posted @ 2013-08-07 10:13 l851654152 阅读(5902) 评论(0) 推荐(0) 编辑
上一页 1 ··· 6 7 8 9 10 11 12 13 14 ··· 24 下一页