使用C ++ Boost库有什么优势?

时间:2020-03-06 14:38:39  来源:igfitidea点击:

因此,我一直在阅读,看来Boost库在实践中得到了很多使用(尽管不是在我的商店里)。为什么是这样?是什么让它如此美妙?

解决方案

我使用文件系统库退出了一些,boost :: shared_ptr非常漂亮。我听说它也做其他事情。

因为C ++标准库还不够完善。

由于它们向标准库中添加了许多缺失的内容,因此其中的一些东西已包含在标准中。

助人不撒谎:

Why should an organization use Boost?
  
  In a word, Productivity. Use of
  high-quality libraries like Boost
  speeds initial development, results in
  fewer bugs, reduces
  reinvention-of-the-wheel, and cuts
  long-term maintenance costs. And since
  Boost libraries tend to become de
  facto or de jure standards, many
  programmers are already familiar with
  them.
  
  Ten of the Boost libraries are
  included in the C++ Standard Library's
  TR1, and so are slated for later full
  standardization. More Boost libraries
  are in the pipeline for TR2. Using
  Boost libraries gives an organization
  a head-start in adopting new
  technologies.
  
  Many organization already use programs
  implemented with Boost, like Adobe
  Acrobat Reader 7.0.

Boost之所以被广泛使用,是因为:

  • 它是开源的,并且经过同行评审。
  • 它提供了STL缺少的广泛的平台不可知功能。
  • 它是对STL的补充,而不是替代。
  • 许多Boost开发人员都在C ++标准委员会中。实际上,Boost的许多部分都被认为包含在下一个C ++标准库中。
  • 它被很好地记录在案。
  • 它的许可证允许将其包含在开放源代码和封闭源代码项目中。
  • 它的功能通常并不相互依赖,因此我们只能链接所需的零件。 [卢克·赫米特(Luc Hermitte)的评论]

Boost基本上是标准将成为标准的内容提要,此外,Boost还具有所有同行评审和使用的功能,因此我们可以肯定,依赖关系可以得到很多好处。

但是,大多数商店都不使用Boost,因为Boost是一个外部依赖项。实际上,减少外部依赖性也很重要。

它添加了允许对C ++编程采用更现代方法的库。

以我的经验,许多C ++程序员实际上是1990年代初期的C ++程序员,几乎编写C ++类,而没有大量使用泛型。更现代的方法是使用泛型将软件组合在一起,就像动态语言一样,但是最终仍然可以进行类型检查/性能检查。看起来有点难看。但是一旦我们克服了语法问题,它的确是相当不错的。 Boost提供了许多轻松组成内容所需的工具。智能指针,函数,lambda,绑定等。然后是boost库,它们利用这种较新的C ++编写方式来提供诸如网络,正则表达式等之类的东西。

如果我们正在编写大量的for循环,手动滚动函数对象或者进行内存管理,那么我们绝对应该检查一下boost。

Boost对C ++有点像.NET Framework对C#,但也许规模较小。

一些Boost类非常有用(shared_ptr),但我认为它们在Boost中具有一些特质和概念。与任何模板繁多的代码一样,Boost的编译时间和巨大的二进制大小完全是疯狂的。必须保持平衡。我不确定Boost是否找到了它。

任何与凯夫琳·亨尼(Kevlin Henney)参与的事情都应引起注意。

在主页上:

"...one of the most highly regarded and expertly designed C++ library projects in the world."
  — Herb Sutter and Andrei Alexandrescu, C++ Coding Standards
  
  "Item 55: Familiarize yourself with Boost."
  — Scott Meyers, Effective C++, 3rd Ed.
  
  "The obvious solution for most programmers is to use a library that provides an elegant and efficient platform independent to needed services. Examples are BOOST..."
    — Bjarne Stroustrup, Abstraction, libraries, and efficiency in C++

因此,它是一系列广泛使用和接受的库,但是为什么需要它呢?

如果你需要:

  • 正则表达式
  • 功能绑定
  • lambda函数
  • 单元测试
  • 智能指针
  • 不可复制,可选
  • 序列化
  • 通用日期
  • 可移植文件系统
  • 循环缓冲区
  • 配置工具
  • 通用图像库
  • TR1
  • 线程数
  • 布拉斯

以及更多使用C ++进行编码时,请看一下Boost。