共 17 篇文章
显示摘要每页显示  条
程序中构造对象统一使用 c++11 的 {} 方式,虽然 () 依然使用,比如 count{value} 和 count(value),lock{mutex} 和 lock(mutex) 都是可以的;赶脚这个才是更自然的 semaphore 的实现,O__O"…。me 测试了一下 semaphore 作为 mutex 使用(默认),去同步四个线程,每个线程 ++sum 100000 次,发现不带 wakeups 的简单版本,速度很慢, 20秒...
clock and time C++11 provides chrono library to deal with clock and time.4) ctime interfaces5) Conversions between Timepoints and Calendar Time#include <chrono>#include <ctime>#include <string>// convert timepoint of system clock to calendar time stringinline std::string asString (const std::chrono:...
ENSURE宏使得我们开发过程中对错误的处理变得极其简单,任何地方你认为需要assert的,用ENSURE就行了,一行简单的ENSURE,把bug相关的三大重要信息全部记录在案,而且由于ENSURE是基于异常的,所以没有办法被程序忽略,也就不会导致难以调试的二阶三阶bug,此外异常不像错误代码需要手动去传递,也就不会带来为了错误处理而造成的额外的开发成...
函数式编程。higher order function 高阶函数:所谓高阶函数就是函数当参数,把传入的函数做一个封装,然后返回这个封装函数。num =[2, -5, 9, 7, -2, 5, 3, 1, 0, -3, 8]positive_num_cnt = 0positive_num_sum = 0for i in range(len(num)): if num[i] >0: positive_num_cnt += 1 positive_num_sum += num[i]if positive_...
C:\Windows\system32\cmd.exe /c lambda_vs_bind.exeAccumulate (lambda) 20001Accumulate (bind) 110007Accumulate (bound lambda) 50003Accumulate (bind_auto) 90005Hit any key to close this window...
//注:cref 的意思是常量引用,也就是说不能改变该引用,也可以直接使用ref()则可以改变 n = 10; f1(1, 2, 1001); // 1 is bound by _1, 2 is bound by _2, 1001 is unused // nested bind subexpressions share the placeholders auto f2 = std::bind(f, _3, std::bind(g, _3), _3, 4, 5); f2(10, 11, 12); // bind to a member function Foo ...
std::cout <<"sp1.unique() == " <<std::boolalpha <<sp1.unique() <<std::endl;std::cout <<"sp1.use_count(): "<< sp1.use_count()<<std::endl;std::cout <<"*sp2: "<< *sp2 <<std::endl;C:\Windows\system32\cmd.exe /c shared_ptr.exesp1.uniq...
// fill 函数,设置array内部的所有元素为指定值#include <iostream>#include <array> int main () { std::array<int,6> myarray; myarray.fill(5); std::cout <<"myarray contains:"; for ( int& x : myarray) { std::cout <<" " <<x; } std::cout <<std::endl; return 0;...
} if (flag == M) { cout<< "recv task try to wake up RecieveTask!pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER;
帮助 | 留言交流 | 联系我们 | 服务条款 | 下载网文摘手 | 下载手机客户端
北京六智信息技术股份有限公司 Copyright© 2005-2024 360doc.com , All Rights Reserved
京ICP证090625号 京ICP备05038915号 京网文[2016]6433-853号 京公网安备11010502030377号
返回
顶部