
boost
文章平均质量分 76
sword_zjcj
这个作者很懒,什么都没留下…
展开
-
boost::shared_ptr在类和容器中使用
#include "stdafx.h"#include #include #include #include using std::vector;using std::cout;using std::endl;using std::ends;// 成员全部是内置类型,默认构造函数将其全初始化为0struct Test{ int i; double d; int* p原创 2015-01-06 17:47:56 · 735 阅读 · 0 评论 -
使用boost::property_tree::ptree读写ini文件
// 参考资料:http://www.cnblogs.com/lidabo/p/3906069.html// http://blog.youkuaiyun.com/ufe_1/article/details/8032089#include "stdafx.h" #include #include #include int main() { boost::property原创 2014-12-27 10:40:32 · 5936 阅读 · 0 评论 -
BOOST_TYPEOF和BOOST_AUTO
头文件里定义了两个宏:BOOST_TYPEOF和BOOST_AUTO,分别用于仿真C++新标准的typeof和auto关键字,可以在编译期自动推导表达式的类型。它们不仅能够推导C++语言内建的int、double、数组、函数指针等等类型,也支持标准库中的容器类型,使程序员再也不需要写复杂的类型定义就能够轻松声明变量。这两个宏完全模仿了typeof和auto关键字的用法,除了因为宏的语法转载 2014-12-27 10:12:34 · 595 阅读 · 0 评论 -
boost::condition的使用
代码来自:http://stlchina.huhoo.net/twiki/bin/view.pl/Main/BoostThread// boost_thread之条件变量// http://stlchina.huhoo.net/twiki/bin/view.pl/Main/BoostThread #include "stdafx.h"#include #include #in原创 2014-12-26 11:27:15 · 1123 阅读 · 0 评论 -
boost::serialization::singleton单例的使用方式
#include "stdafx.h"#include #include #include // 使用方式1:模板参数方式class CTest:public boost::noncopyable // 不能复制、赋值{public: void Set(int i){ m_val = i; } void Print() const{ std::cout<<m_val<<std:原创 2014-12-26 14:10:59 · 6208 阅读 · 0 评论 -
BOOST_FOREACH缺陷
以下来自手册:缺陷本节描述 BOOST_FOREACH 中的一些常见的缺陷。 带逗号的类型 由于 BOOST_FOREACH 是一个宏,它必须刚好有两个参数,并以一个逗号分隔它们。这并不总是很方便,尤其当循环变量的类型是一个模板的时候。考虑一下对std::map 进行迭代:std::mapint,int> m;// 错误!BOOST_FOREACH 宏参原创 2014-12-26 09:57:53 · 1319 阅读 · 0 评论 -
boost::thread的简单应用
// boost_thread.cpp : 定义控制台应用程序的入口点。// thread是一个跨平台的线程封装库// 参考资料:http://blog.youkuaiyun.com/zhuxiaoyang2000/article/details/6588031// http://blog.youkuaiyun.com/gitar520/article/details/7694984// http://blog.原创 2014-12-25 17:28:50 · 547 阅读 · 0 评论 -
boost中的condition_variable (条件变量)的使用
代码基本来自boost手册,进行了稍微的修改和备注#include #include using std::cout;using std::endl;boost::condition_variable cond; // 条件变量boost::mutex mut; // 互斥量,使用他来进行线程同步bool data_ready; // 公共对象void process_da原创 2014-12-25 17:22:24 · 5161 阅读 · 0 评论 -
boost asio异步读写网络聊天室【官方示例】
//// chat_message.hpp// ~~~~~~~~~~~~~~~~//// Copyright (c) 2003-2010 Christopher M. Kohlhoff (chris at kohlhoff dot com)//// Distributed under the Boost Software License, Version 1.0. (See accom原创 2014-12-20 14:50:33 · 3542 阅读 · 0 评论 -
boost::asio socket同步实现聊天示例
客户端:client#include #include using namespace boost::asio;int main(int argc, char* argv[]){ // 所有asio类都需要io_service对象 io_service iosev; // socket对象 ip::tcp::socket socket(iosev); // 连接端点,原创 2014-12-20 15:17:44 · 994 阅读 · 0 评论 -
使用enable_shared_from_this
使用enable_shared_from_this说明The header defines the class template enable_shared_from_this. It is used as a base class that allows a shared_ptr to the current object to be obtained from within a转载 2014-12-20 15:13:09 · 641 阅读 · 0 评论 -
boost::ASIO的异步方式
嗯?异步方式好像有点坐不住了,那就请异步方式上场,大家欢迎...大家好,我是异步方式和同步方式不同,我从来不花时间去等那些龟速的IO操作,我只是向系统说一声要做什么,然后就可以做其它事去了。如果系统完成了操作, 系统就会通过我之前给它的回调对象来通知我。在ASIO库中,异步方式的函数或方法名称前面都有“async_” 前缀,函数参数里会要求放一个回调函数(或仿函数)。异转载 2014-12-20 15:10:24 · 2131 阅读 · 0 评论 -
boost::noncopyable
// 参考资料:http://blog.youkuaiyun.com/huang_xw/article/details/8248960#include "stdafx.h"#include // 除非自定义复制、赋值成员(但这样就不应该派生自boost::noncopyable)// 否则不允许复制、赋值,对应成员函数在boost::noncopyable类中为privateclass mycl转载 2014-12-27 10:05:58 · 577 阅读 · 0 评论