XuQi's Blog

  • 首页

  • 归档

Boost基础知识

发表于 2018-05-17 更新于 2019-10-20

BoostDemo

1. 下载编译使用

下载地址

1
./bootstrap.sh;./b2

第一条命令bootstrap.sh是编译前的配置工作,第二条命令b2开始

Makefile:

1
2
3
CFLAGS= -std=c++11 					#Linux应使用gnu++0x
INCLUDE=I/Users/chrono/boost/ #Boost库安装在用户主目录
STDLIB= -stdlib=libc++ #Linux无需此FLAG

XCode配置:

2. Timer库

  • timer
  • progress_display
处理日期
1
2
3
#define BOOST_DATE_TIME_SOURCE
#include <boost/date_time/gregorian/gregorian.hpp>
using namespace boost::gregorian;
  • date
  • date_period
处理时间
1
2
#include <boost/date_time/posix_time/posix_time.hpp>
using namespace boost::posix_time;
  • hours
  • minutes
  • seconds
  • milliseconds
  • time_duration
  • ptime
  • time_period

3. 内存管理

smart_ptr库
  • Raii机制 (资源获取就是初始化)
  • 智能指针
1
2
#include <boost/smart_ptr.hpp>
using namespace boost;
  • 自动指针
1
auto_ptr<ClassA> a(new ClassA);
XCode 编译器配置为C++11

13

C++98
  • auto_ptr
boost.smart_ptr (6种智能指针)
  • scoped_ptr (不能赋值,比较,可以使用unique_ptr替代,不可以使用容器)
  • scoped_array (不推荐使用)
  • share_ptr (引用计数,可以赋值,可以放入容器) make_share 不使用new 创建对象
  • share_array
  • weak_ptr (打破循环引用)
  • intrusive_ptr (不推荐使用)
C++11
  • unique_ptr (可以比较,不允许赋值,可以放入容器)
  • share_ptr
  • weak_ptr

pool

  • pool
  • object_pool
  • singleton_pool
  • pool_alloc

实用工具

  • noncopyable

  • typeof

    C++ 11

    • auto
    • decltype

    Boost

    1
    #include<boost/typeof/typeof.hpp>
- BOOST_TYPEOF
- BOOST_AUTO
# Boost信
Esp8266和HomeKit
shadowsocks
  • 文章目录
  • 站点概览

XuQi

44 日志
30 标签
  1. 1. BoostDemo
    1. 1.1. 1. 下载编译使用
    2. 1.2. 2. Timer库
      1. 1.2.0.1. 处理日期
      2. 1.2.0.2. 处理时间
  2. 1.3. 3. 内存管理
    1. 1.3.1. smart_ptr库
    2. 1.3.2. XCode 编译器配置为C++11
    3. 1.3.3. C++98
    4. 1.3.4. boost.smart_ptr (6种智能指针)
    5. 1.3.5. C++11
  3. 1.4. pool
  • 2. 实用工具
  • © 2019 XuQi
    由 Hexo 强力驱动 v3.9.0
    |
    主题 – NexT.Muse v7.3.0