Boost C++ Libraries

下载地址:http://sourceforge.net/projects/boost/files/boost/1.51.0/

Boost C++ 库(Libraries)是一组扩充C++功能性的经过同行评审(Peer-reviewed)且开放源代码程序库。大多数的函数为了能够以开放源代码、封闭专案的方式运作,而授权于Boost软件授权条款(Boost
Software License)之下。许多Boost的开发人员是来自C++标准委员会,而部份的Boost库成为C++的TR1标准之一。[1]

为了要确保库的效率与弹性,Boost广泛的使用模板(template)功能。而它是针对各式领域的C++用户与应用领域(Application Domain)上,包含的库类型从像smart_ptr
这种类通用库,到像是文件系统操作系统抽象层,甚至能够利用Boost来开发额外的库或是给高级的C++用户利用,像是MPL

目录

内容

容器

正当性与测试

数据结构

语言之间的支持(Python用)

  • iterator
  • 数学和计算
  • 存储器(memory)
    • pool - 内存池,boost提供4种内存池模型供使用:pool、object_pool、singleton_pool、pool_allocator/fast_pool_allocator。
    • smart_ptr - boost的smart_ptr中提供了4种智能指针,作为std::auto_ptr的补充。
      • scoped_ptr - 具作用域指针,与std::auto_ptr类似,但不能转让所有权,用于确保离开作用域能够正确地删除动态分配的对象。
      • scoped_array - 配合scoped_ptr使用。
      • shared_ptr -
      • shared_array - 配合shared_ptr使用。
      • weak_ptr - shared_ptr 的观察者,避免shared_ptr循环引用,是一种辅助指针。
      • intrusive_ptr - 比 shared_ptr 更好的智能指针。
    • utility - 以下是utility类型的定义。

并行计算

其他

模板元编程(Template
Metaprogramming)

范例

现有的 Boost 包含 87 种不同的函数库,以下面几项做范例:

线性代数 – uBLAS

Boost 包含了 uBLAS
线性代数
函数库,能够借由基本函数库子函数(BLAS)来支持矢量与矩阵形运算。

  • 此范例表示如何矩阵与矢量作乘积:
 
#include <boost/numeric/ublas/vector.hpp>
#include <boost/numeric/ublas/matrix.hpp>
#include <boost/numeric/ublas/io.hpp>
#include <iostream>
 
using namespace boost::numeric::ublas;
 
/* 举例 "y = Ax"  */
int main () 
{
      vector<double> x (2);
      x(0) = 1; x(1) = 2;
 
      matrix<double> A(2,2);
      A(0,0) = 0; A(0,1) = 1;
      A(1,0) = 2; A(1,1) = 3;
 
      vector<double> y = prod(A, x);
 
      std::cout << y << std::endl;
      return 0;
}

随机数产生 – Boost.Random

Boost 也提供独立分布的模拟随机与 PRNG 独立性的机率分布,而这些能够具体的创建产生器。

#include <boost/random.hpp>
#include <ctime>
 
using namespace boost;
 
double SampleNormal (double mean, double sigma)
{
    // 建立一个 Mersenne twister 随机数产生器
    // 从 1970 年到现在的 #seconds 设定 seed
    static mt19937 rng(static_cast<unsigned> (std::time(0)));
 
    // 选择高斯机率分布
    normal_distribution<double> norm_dist(mean, sigma);
 
    // 使用 function 的形式,生成随机数据产生器
    variate_generator<mt19937&, normal_distribution<double> >  normal_sampler(rng, norm_dist);
 
    // 传回样本分布结果
    return normal_sampler();
}

更详细的说明请参阅
Boost 随机数库

多线程 – Boost.Thread

示例码演示创建运行绪:

#include <boost/thread/thread.hpp>
#include <iostream>
 
using namespace std; 
 
void hello_world() 
{
  cout << "Hello world, I'm a thread!" << endl;
}
 
int main(int argc, char* argv[]{
  // 開始一條使用 "hello_world" function 的新執行緒
  boost::thread my_thread(&hello_world);
  // 等待執行緒完成工作
  my_thread.join();
 
  return 0;
}

引用

外部链接

Wikibooks-logo.svg
您可以在维基教科书中查找此百科条目的相关电子教程:

百度百科:

Boost中比较有名气的有这么几个库:  

Regex  正则表达式库  

Spirit  LL parser framework,用C++代码直接表达EBNF  

Graph  图组件和算法  

Lambda  在调用的地方定义短小匿名的函数对象,很实用的functional功能  

concept check  检查泛型编程中的concept  

Mpl  用模板实现的元编程框架  

Thread  可移植的C++多线程库  

Python  把C++类和函数映射到Python之中  

Pool  内存池管理  

smart_ptr  5个智能指针,学习智能指针必读,一份不错的参考是来自CUJ的文章:

种类

  按照功能分类的Boost库列表  按照实现的功能,Boost可为大致归入以下20个分类,在下面的分类中,有些库同时归入几种类别。  

1. 字符串和文本处理  a) Conversion  b) Format  c) IOStream  d) Lexical Cast  e) Regex  f) Spirit  g) String Algo  h) Tokenizer 

      i) Wave  j) Xpressive  

2. 容器  a) Array  b) Bimap  c) Circular Buffer  d) Disjoint Sets  e) Dynamic Bitset  f) GIL  g) Graph  h) ICL  i) Intrusive 

      j) Multi-Array  k) Multi-Index  l) Pointer Container  m) Property Map  n) Property Tree  o) Unordered  p) Variant  

3. 迭代器  a) GIL  b) Graph  c) Iterators  d) Operators  e) Tokenizer  

4. 算法  a) Foreach  b) GIL  c) Graph  d) Min-Max  e) Range  f) String Algo  g) Utility  

5. 函数对象和高阶编程  a) Bind  b) Function  c) Functional  d) Functional/Factory  e) Functional/Forward  f) Functional/Hash  g) Lambda 

      h) Member Function  i) Ref  j) Result Of  k) Signals  l) Signals2  m) Utility  

6. 泛型编程  a) Call Traits  b) Concept Check  c) Enable If  d) Function Types  e) GIL  f) In Place Factory, Typed In Place Factory  

        g) Operators  h) Property Map  i) Static Assert  j) Type Traits  

7. 模板元编程  a) Function Types  b) Fusion  c) MPL  d) Proto  e) Static Assert  f) Type Traits  

8. 预处理元编程  a) Preprocessors  

9. 并发编程  a) Asio  b) Interprocess  c) MPI  d) Thread  

10. 数学和数字  a) Accumulators  b) Integer  c) Interval  d) Math  e) Math Common Factor  f) Math Octonion  g) Math Quaternion  

         h) Math/Special Functions  i) Math/Statistical Distributions  j) Multi-Array  k) Numeric Conversion  l) Operators  m) Random  

         n) Rational  o) uBLAS  

11. 排错和测试  a) Concept Check  b) Static Assert  c) Test  

12. 数据结构  a) Any  b) Bitmap  c) Compressed Pair  d) Fusion  e) ICL  f) Multi-Index  g) Pointer Container  h) Property Tree 

       i) Tuple  j) Uuid  k) Variant  

13. 图像处理  a) GIL  

14. 输入输出  a) Asio  b) Assign  c) Format  d) IO State Savers  e) IOStreams  f) Program Options  g) Serialization  

15. 跨语言混合编程  a) Python  

16. 内存管理  a) Pool  b) Smart Ptr  c) Utility  

17. 解析  a) Spirit  

18. 编程接口  a) Function  b) Parameter  

19. 杂项  a) Compressed Pair  b) Conversion  c) CRC  d) Date Time  e) Exception  f) Filesystem  g)
Flyweight  h) Lexical Cast  

         i) Meta State Machine  j) Numeric Conversion  k) Optional  l) Polygon  m) Program Options  n) Scope Exit  o) Statechart  

         p) Swap  q) System  r) Timer  s) Tribool  t) Typeof  u) Units  v) Utility  w) Value Initialized  

20. 编译器问题的变通方案  a) Compatibility  b) Config  

原文链接: https://www.cnblogs.com/ajian005/archive/2012/11/01/2753636.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

    Boost C++ Libraries

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/67774

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月9日 下午12:58
下一篇 2023年2月9日 下午1:00

相关推荐