Boost 的最佳组件是什么?

发布于 2024-07-14 10:38:25 字数 707 浏览 15 评论 0原文

我一直在浏览 Boost 库的版本 1.38.0,试图确定其中是否有足够的精华来证明我公司的外部软件审批流程的谈判是合理的。 在编写测试程序和阅读文档的过程中,我

  • 当然得出了一些结论,并不是 Boost 中的所有内容都将在我的工程组中使用,
  • 更重要的是,其中一些库看起来比其他库更精致

事实上,有些图书馆对我来说有点像玩具。

有许多相当容易访问的库,我在经过短暂的调查后就可以看到它们的使用,例如 boost::variant (我真的很喜欢 visitor 组件事实上,如果访问者缺少其中一种变体类型的运算符,则编译器会报错)。 我会使用boost::shared_ptr,除了我们组已经拥有一组智能指针类型这一事实。

那么根据 Stack Overflow 用户的广泛经验,哪些 Boost 库

  • 具有较高的质量呢?
  • 不仅仅是玩具?
  • 有哪些入门门槛高但值得学习的?

请注意,这是一个与 Boost 被认为有害? 中提出的问题有些不同的问题

PS - 有以下之一答案(来自 litb)已被删除? 我在这里看不到它,只有我的用户页面上的摘录......

I've been browsing revision 1.38.0 of the Boost libraries, in an attempt to decide if there are enough jewels there to justify negotiating my company's external software approval process. In the course of writing test programs and reading the documents, I've reached a couple conclusions

  • of course, not everything in Boost will ever be of use in my engineering group
  • more importantly, some of these libraries seem more polished than others

In fact, some libraries seem a bit toy-like to me.

There are a number of fairly accessible libraries that I can see putting to use after only a short period of investigation, such as boost::variant (I really like the visitor component and the fact that the compiler barfs if a visitor lacks an operator for one of the variant types). I'd use boost::shared_ptr except for the fact that our group already has a set of smart pointer types.

So based on the broad experience of Stack Overflow users, which Boost libraries

  • have high quality?
  • are more than toys?
  • are there any which have a high entry barrier but which are well worth learning?

Note that this is a somewhat different question than that posed in Boost considered harmful?

P.S. - Has one of the answers (from litb) been deleted? I can't see it here, and only an excerpt on my user page...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

冷弦 2024-07-21 10:38:25

我经常使用(它让我的生活更简单):

  • 智能指针(shared_ptrscoped_ptrweak_ptr、进程间unique_ptr):

    • scoped_ptr 用于基本 RAII(无共享所有权和所有权转让),免费。
    • shared_ptr 用于更复杂的操作 - 当需要共享所有权时。 不过,这也是有一定成本的。
    • unique_ptr - boost 正在积极致力于通过移动模拟将各种方法(Boost 中提供)统一为 unique_ptr
    • 它们非常易于使用(仅标头)、易于学习且经过充分测试(嗯,除了 unique_ptr
  • Boost Thread - 积极开发(线程现在可移动)库用于工作与线程。 隐藏给定平台上线程实现的复杂性。

  • Boost MPL 和 Fusion - 这些更难以解释。 很长一段时间我没有使用编译时功能,但经过一些阅读和学习后发现我的一些代码可以很好地简化。 不过,请注意编译时间...

  • Boost Asio

    • 与第一印象相反(至少在不久前),它不仅仅是网络库。 它提供了几乎可用于任何事物的异步 I/O 模型。
  • Boost Format(强大的输出格式化,但非常繁重)

  • Boost Spirit2x(Karma 和 Qi 都用于根据给定语法解析和生成输出)。 真的很强大,可以创建一个解析器而不需要借助外部工具。 然而编译时间可能是一个问题。 此外,版本 2x 正在积极开发中,文档相当稀缺(尽管spirit-devel 邮件列表非常有帮助)

  • Boost Bind、Function 和 Lambda 让您的生活更轻松,Boost Phoenix - 只是为了实验

  • lexical_cast (类似的东西可能很快就会像 boost::string 一样诞生)

  • Regex/Xpressive - 正则表达式

  • 键入特征和概念检查 - 再次让您的生活更轻松

  • 数学:

    • 各种随机数生成器
    • 各种统计分布
    • ublas - 用于以类似 C++ 的方式使用 LAPACK/BLAS 绑定
    • 一些数学函数,通常在 C++ 中不可用
    • 一些用于控制数字类型之间转换的工具
    • 区间算术
  • Boost Iterator (用于创建您自己的迭代器和外观的专用适配器)

  • Boost 单元测试框架

还有一些我在 Boost 中几乎没有接触过的部分。 也许我还忘记提及一些明显的问题。

请记住使用正确的工具(锤子)解决正确的问题(钉子)。 请记住保持解决方案简单。 请记住所接收功能的成本(例如 shared_ptrboost::format 运行时开销或 MPL/Fusion/Spirit/Phoenix 编译时间成本和可执行文件大小)。 但尝试和学习——这就是乐趣所在。

当谈到说服管理层使用新库时,您不必从所有库开始。 从简单的事情开始(可能是那些具有长期稳定的 Boost 历史、广泛的编译器支持、计划包含在 TR2/C++1x 等中的事情)和显示其优点的简单示例。

I use quite frequently (and it makes my life simpler):

  • smart pointers (shared_ptr, scoped_ptr, weak_ptr, interprocess unique_ptr):

    • scoped_ptr for basic RAII (without shared ownership and ownership transfer), at no cost.
    • shared_ptr for more complex operations - when shared ownership is needed. However there is some cost.
    • unique_ptr - there is active work at boost on unifying various approaches (present at Boost) to unique_ptr with move emulation.
    • They are really simple to use (header only), easy to learn and very well tested (well, except maybe the unique_ptr)
  • Boost Thread - actively developed (threads are now movable) library for working with threads. Hides the complexity of thread implementation on a given platform.

  • Boost MPL and Fusion - these are more difficult to explain. For long time I didn't use compile time power, but after some reading and learning it turned out that some of my code can be nicely simplified. Still, beware of the compilation time...

  • Boost Asio

    • Contrary to the first impression (at least some time ago) it is not only the networking library. It provides asynchronous I/O model that can be used for virtually anything.
  • Boost Format (powerful output formatting, but very heavy)

  • Boost Spirit2x (Karma and Qi used both for parsing and generating output based on a given grammar). Really powerful, can create a parser without resorting to external tools. Yet the compilation time might be a problem. Also version 2x is being actively developed and the documentation is rather scarce (the spirit-devel mailing list is very helpful though)

  • Boost Bind, Function and Lambda to make your life easier and Boost Phoenix - just to experiment

  • lexical_cast (something similar might be born soon as boost::string)

  • Regex/Xpressive - regular expressions

  • Type traits and concept checks - once again to make your life easier

  • Math:

    • various random number generators
    • various statistical distributions
    • ublas - for using LAPACK/BLAS bindings in C++ like way
    • some mathematical functions, normally not available in C++
    • some tools for controlling the conversions between numreric types
    • interval arithmetics
  • Boost Iterator (specialized adaptors for iterators and facade for creating your own)

  • Boost Unit Testing framework

And still there are some parts that I'd barely touched in Boost. Probably I also forgot to mention few obvious ones.

Remember to use right tools (hammers) for right problems (nails). Remember to keep the solutions simple. Remember about the cost of received functionality (for example shared_ptr or boost::format runtime overhead or MPL/Fusion/Spirit/Phoenix compile time costs and executable sizes). But experiment and learn - it's where the fun is.

And when it comes to convincing the management to use the new libraries - you don't have to start with all the libraries. Start with the simple things (probably the ones that have a long and stable Boost history, broad compiler support, are planned for inclusion in TR2/C++1x, etc) and simple examples that show the benefits.

ˉ厌 2024-07-21 10:38:25

我发现在设计跨平台(例如 *nix 和 win32)多线程应用程序时,boost 是无可争议的必备boost::thread) code>、boost::interprocess。)仅此一点就足以证明我在至少一个例子中采用 boost 作为我雇主项目的一部分。

其余的(容器、通用编程和元编程、内存)则作为免费赠品。

I found boost to be an uncontested must-have when designing cross-platform (e.g. *nix and win32) multi-threaded apps (boost::thread, boost::interprocess.) This alone has been justification enough in at least one instance for adopting boost as part of my employers' projects.

The rest (containers, generic programming and meta-programming, memory) followed as freebies.

骄兵必败 2024-07-21 10:38:25

我经常使用 boost::filesystem。 它完成了简单文件管理所需的一切

I often use boost::filesystem. It does all necessary for simple file management

国粹 2024-07-21 10:38:25

我想说有价值的库是:

  • 元编程(MPL、enable_iftype/function_traits
  • 预处理器 - 如果您需要它,它可能会很方便的
  • 变体,可选 - 根据您的需要已经注意到
  • 数学 - 四元数,额外的数学函数(尽管它们可能对你没有用)
  • lambda:虽然语法很复杂,但它很容易上瘾
  • 运算符/迭代器:它们在构造你自己的类型时真的很方便

也许Python(从未尝试过,但是一些 KDE 程序使用它)

I'd say the valuable libraries are:

  • Metaprogramming (MPL, enable_if, type/function_traits)
  • Preprocessor - if you need it, it may come handy
  • variant, optional - as you already noted
  • Math - quaternions, extra math functions (although they might not be useful to you)
  • lambda: although the syntax is hairy, it's pretty addictive
  • operators/iterators: they are really handy when constructing your own types

Maybe Python (never tried, but some eg. KDE programs use it)

紙鸢 2024-07-21 10:38:25

Boost interprocess 如果你正在做事情的话绝对值得带共享内存和 类似。

Boost interprocess is definitely worth it if you are doing things w/ shared memory & the like.

饮惑 2024-07-21 10:38:25

如果您使用 STL,Boost::lambda 会有一定帮助。 它使您能够就地创建谓词,如下所示:

for_each(a.begin(), a.end(), std::cout << _1 << ' ');

此代码输出容器中以空格分隔的所有元素。

Boost::lambda is somewhat helpful if you use STL. It enables you to create predicates in place, like this:

for_each(a.begin(), a.end(), std::cout << _1 << ' ');

This code outputs all elements from container separated by spaces.

傾城如夢未必闌珊 2024-07-21 10:38:25

C++0x 标准库的许多新增内容最初是作为 Boost 库的一部分创建的。

它们并不完美(任何软件都是如此),但所使用的工程过程非常强大(远远超过大多数免费软件)。 如果您确实需要帮助,您可以在邮件列表上找到很多帮助。

Many of the additions to the C++0x standard library were first created as part of the Boost libraries.

They are not perfect (is any software) but the engineering process used is pretty robust (far more than most free software). If you do need help, you will find plenty on the mailing list.

椵侞 2024-07-21 10:38:25

我个人认为你应该看一下隐藏平台特定内容的库,如线程、ipc、内存映射文件、文件系统、异步 IO 等。

这些可以为你在多平台项目中节省大量时间和麻烦,并且往往集中于公开功能而不是花哨的 C++ 功能的练习。

I personally think you should take a look at libraries that hides platform specific stuff like threading, ipc, memory mapped files, file system, asynchronous IO etc.

These can save you lots of time and trouble in multi platform projects and tends to be focused on exposing functionality rather than exercises in fancy C++ features.

来世叙缘 2024-07-21 10:38:25

如果您需要解析比简单键/值对更复杂的文本文件,我强烈推荐 Boost::spirit。 它的学习曲线很高,但一旦你弄清楚了,它就可以让你轻松地将 EBNF 语法嵌入到代码中。 它比编写自己的解析器要健壮得多。 我还发现自己创建的文件格式更多地是为了文件编写者的方便而不是解析代码的编写者而设计的。

If you need to parse text files that are more complex that simple key/value pairs, I highly recommend Boost::spirit. It has a high learning curve, but once you figure it out, it lets you easily embed EBNF grammers right in the code. Its much more robust than writing your own parser. I also find myself creating file formats that are designed more for the ease of the writer of the file than the writer of the parsing code.

梦明 2024-07-21 10:38:25

我发现 boost.thread 和 boost.asio 对于编写客户端/服务器应用程序不可或缺。 智能指针库可以轻松编写使用异常处理而不会泄漏内存的代码。

顺便说一句,最近发布了一组 PDF 文件,记录了一些更常见的 boost 库。 您可以从 SourceForge 下载它们。

I have found boost.thread and boost.asio indispensable for writing client/server applications. The smart pointer library makes it easy to write code that uses exception handling without leaking memory.

On a side note, a set of PDF files documenting some of the more common boost libraries has been released recently. You can download them from SourceForge.

纵情客 2024-07-21 10:38:25

我已阅读其他答案,并且我需要添加 Boost.Graph (BGL) 及其朋友 Boost.Property_map。 这两个确实改变了我的日常工作。

它的设计非常好,但大多数人一开始都被推迟了,因为在真正理解所有概念的目的之前要付出相当高的代价。 但是一旦你掌握了这个库,就很难离开它!

I've read the other answers and I need to add Boost.Graph (BGL) and its friend Boost.Property_map. These two literally changed my everyday work.

It is extremely well designed, but most people are put off at first because there is quite a high price to pay before actually understanding the purpose of all concepts. But once you get a grip on this library, it becomes hard to go without !

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文