使用 C++ Boost 库的优势是什么?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/125580/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-27 13:03:10  来源:igfitidea点击:

What are the advantages of using the C++ Boost libraries?

c++boost

提问by jdt141

So, I've been reading through and it appears that the Boost libraries get used a lot in practice (not at my shop, though). Why is this? and what makes it so wonderful?

所以,我一直在阅读,似乎 Boost 库在实践中得到了很多使用(虽然不是在我的商店)。为什么是这样?是什么让它如此美妙?

回答by blackwing

Boostis used so extensively because:

Boost被如此广泛地使用是因为:

  • It is open-source and peer-reviewed.
  • It provides a wide rangeof platform agnostic functionality that STL missed.
  • It is a complement to STL rather than a replacement.
  • Many of Boost developers are on the C++ standard committee. In fact, many parts of Boost is considered to be included in the next C++ standard library.
  • It is documented nicely.
  • Its licenseallows inclusion in open-source and closed-source projects.
  • Its features are not usuallydependent on each other so you can link only the parts you require. [Luc Hermitte's comment]
  • 它是开源的并经过同行评审。
  • 它提供了STL 错过的广泛的平台无关功能。
  • 它是对 STL 的补充而不是替代。
  • 许多 Boost 开发人员都在 C++ 标准委员会。事实上,Boost 的很多部分都被认为包含在下一个 C++ 标准库中。
  • 它被很好地记录下来。
  • 它的许可证允许包含在开源和闭源项目中。
  • 它的特点是不通常依赖于对方,所以你可以只链接您所需要的零件。[吕克·赫米特的评论]

回答by Sébastien RoccaSerra

From the home page:

从主页:

"...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++

“......世界上最受推崇和专业设计的 C++ 库项目之一。” — Herb Sutter 和 Andrei Alexandrescu,C++ 编码标准

“第 55 项:熟悉 Boost。” — Scott Meyers,Effective C++,第 3 版。

“对于大多数程序员来说,显而易见的解决方案是使用一个库,该库提供了一个独立于所需服务的优雅而高效的平台。例如 BOOST...”——Bjarne Stroustrup,C++ 中的抽象、库和效率

So, it's a range of widely used and accepted libraries, but why would you need it?

所以,它是一系列广泛使用和接受的库,但您为什么需要它?

If you need:

如果你需要:

  • regex
  • function binding
  • lambda functions
  • unit tests
  • smart pointers
  • noncopyable, optional
  • serialization
  • generic dates
  • portable filesystem
  • circular buffers
  • config utils
  • generic image library
  • TR1
  • threads
  • uBLAS
  • 正则表达式
  • 函数绑定
  • 拉姆达函数
  • 单元测试
  • 智能指针
  • 不可复制,可选
  • 连载
  • 通用日期
  • 便携式文件系统
  • 循环缓冲区
  • 配置工具
  • 通用图像库
  • TR1
  • 线程
  • uBLAS

and morewhen you code in C++, have a look at Boost.

更多的时候,你的代码在C ++中,看看升压

回答by Vinko Vrsalovic

Because they add many missing things to the standard library, so much so some of them are getting included in the standard.

因为他们向标准库添加了许多缺失的东西,所以其中一些被包含在标准中。

Boost peopleare not lying:

Boost 人没有说谎:

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?

一句话,生产力。使用像 Boost 这样的高质量库可以加速初始开发,减少错误,减少轮子的重新发明,并降低长期维护成本。由于 Boost 库趋向于成为事实上或法律上的标准,许多程序员已经熟悉它们。

10 个 Boost 库包含在 C++ 标准库的 TR1 中,因此将用于以后的完全标准化。更多 Boost 库正在准备用于 TR2。使用 Boost 库可以让组织在采用新技术方面处于领先地位。

许多组织已经在使用通过 Boost 实现的程序,例如 Adob​​e Acrobat Reader 7.0。

回答by Vinko Vrsalovic

A few Boost classes are very useful (shared_ptr), but I think they went a bit nuts with traits and concepts in Boost. Compile times and huge binary sizes are completely insane with Boost, as is the case with any template-heavy code. There has to be a balance. I'm not sure if Boost has found it.

一些 Boost 类非常有用(shared_ptr),但我认为它们对 Boost 中的特征和概念有点疯狂。Boost 的编译时间和巨大的二进制文件大小是完全疯狂的,就像任何模板繁重的代码一样。必须有一个平衡。我不确定 Boost 是否找到了它。

回答by Tony Delroy

BOOST's a collection of libraries filling needs common to many C++ projects. Generally, they do prioritise correctness, reusability, portability, run-time performance, and space-efficiency over readability of BOOST implementation code, or sometimes compile times. They tend not to cover complete high-level functional requirements (e.g. application frameworks), and instead (thankfully) offer building blocks that can be more freely combined without dictating or dominating the application design.

BOOST 是一组库,可满足许多 C++ 项目的共同需求。一般来说,他们确实优先考虑正确性、可重用性、可移植性、运行时性能和空间效率,而不是 BOOST 实现代码的可读性,有时甚至是编译时间。它们往往不涵盖完整的高级功能需求(例如应用程序框架),而是(值得庆幸的是)提供可以更自由地组合的构建块,而不会支配或支配应用程序设计。

The important reasons to consider using BOOST include:

考虑使用 BOOST 的重要原因包括:

  • most libraries are pretty well tested and designed: they generally get a reasonably sound review by some excellent programmers, compared to by people with home-brew solutions in the same problem space, and widely used enough to gather extensive real-world feedback
  • it's already written and your solution probably isn't
  • it's pretty portable (but that varies per library)
  • more people in the C++ community will have a head-start in helping you with your code
  • BOOST is often a proving ground for introduction to the C++ Standard, so you'll have less work to do in rewriting your code to be compatible with future Standards sans BOOST
  • due to the community demand, compiler vendors are more likely to test and react to issues of correctness with BOOST usage
  • familiarity with boost libraries will help you do similar work on other projects, possibly in other companies, where whatever code you might write now might not be available for reuse
  • 大多数库都经过了很好的测试和设计:与在同一问题空间中拥有自制解决方案的人相比,它们通常会得到一些优秀程序员的合理评价,并且被广泛使用以收集广泛的现实世界反馈
  • 它已经写好了,你的解决方案可能不是
  • 它非常便携(但每个图书馆都不同)
  • C++ 社区中的更多人将在帮助您编写代码方面处于领先地位
  • BOOST 通常是介绍 C++ 标准的试验场,因此在没有 BOOST 的情况下,重写代码以与未来标准兼容的工作量会减少
  • 由于社区需求,编译器供应商更有可能对 BOOST 使用的正确性问题进行测试和反应
  • 熟悉 boost 库将帮助你在其他项目上做类似的工作,可能在其他公司,你现在编写的任何代码都可能无法重用

The libraries are described in a line or two here: http://www.boost.org/doc/libs/.

这些库在这里用一两行描述:http: //www.boost.org/doc/libs/

回答by Keith Nicholas

It adds libraries that allow for a more modern approach to C++ programming.

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

In my experience many C++ programmers are really the early 1990s C++ programmers, pretty much writing C++ classes, not a lot of use of generics. The more modern approach uses generics to compose software together in manner thats more like dynamic languages, yet you still get type checking / performance in the end. It is a little bit ugly to look at. But once you get over the syntax issues it really is quite nice. Boost gives you a lot of the tools you need to compose stuff easily. smart pointers, functions, lambdas, bindings, etc. Then there are boost libraries which exploit this newer way of writing C++ to provide things like networking, regex, etc etc...

根据我的经验,许多 C++ 程序员实际上是 1990 年代早期的 C++ 程序员,几乎都在编写 C++ 类,很少使用泛型。更现代的方法使用泛型以更像动态语言的方式将软件组合在一起,但最终您仍然可以获得类型检查/性能。看着有点难看。但是一旦你解决了语法问题,它真的很不错。Boost 为您提供了许多轻松编写内容所需的工具。智能指针、函数、lambda、绑定等。然后还有 boost 库,它们利用这种较新的 C++ 编写方式来提供诸如网络、正则表达式等之类的东西......

if you are writing lots of for loops, or hand rolling function objects, or doing memory management, then you definitely should check boost out.

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

回答by Hans Sjunnesson

Because the C++ standard library isn't all that complete.

因为 C++ 标准库并不是那么完整

回答by Umber Ferrule

Anything with Kevlin Henney's involvement should be taken note of.

任何有Kevlin Henney参与的事情都应该注意。

回答by macbirdie

Boost is to C++ sort of like .NET Framework is to C#, but maybe on a smaller scale.

Boost 之于 C++ 有点像 .NET Framework 之于 C#,但可能规模较小。

回答by Robert Gould

Boost basically the synopsis of what the Standard will become, besides with all the peer review and usage that Boost gets you can be pretty sure your getting quite a good deal for your dependencies.

Boost 基本上是标准将成为什么的概要,除了 Boost 获得的所有同行评审和使用之外,您可以非常确定您为您的依赖项获得了相当多的优惠。

However most shops don't use Boost, because its an External Dependency. And in reality reducing External dependencies is very important as well.

然而,大多数商店不使用 Boost,因为它是一个外部依赖。实际上,减少外部依赖也非常重要。