在学习 BOOST 替代方案之前我应该​​先精通 STL 库吗?

发布于 2024-07-13 20:01:48 字数 108 浏览 6 评论 0原文

在学习 C++ 时将自己限制在 STL 库中,然后在相当精通普通 C++ 后处理 boost 及其附加内容是否有意义?

或者您应该在学习 C++ 的同时直接深入了解 BOOST 吗?

Does it make sense to restrict yourself to the STL libraries when learning C++ and then tackle boost and its additions after you have become fairly proficient with vanilla C++?

Or should you dive right into BOOST while learning C++?

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

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

发布评论

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

评论(9

悲凉≈ 2024-07-20 20:01:48

STL 有一些核心概念。 Boost 建立在它们的基础上并对其进行扩展。 如果您理解它们,那么直接转向 Boost 可能对您有用。 如果没有的话,我会从STL开始。

  • 各种容器类型之间的区别(诸如 vectorlistdeque 等序列,以及诸如 mapmap 等关联code>set 及其 multi*unordered_* 变体)。 有时您可以将其中之一替换为另一种,有时则不能。 了解他们的优势和局限性。
  • 迭代器的作用,以及它们如何在容器和算法之间提供桥梁。 (我发现我一遍又一遍地使用这个)。
  • 为什么存在标准算法:它们通常是少量代码,因此它们存在的原因可能并不明显。 了解它们使用哪些容器,以及如何针对特定情况专门化它们(例如,了解通用 copy 与专门用于 const char *copy 有何不同>)。
  • 如何以及何时使用特征类。
  • 如何使用绑定器(bind1stptr_funmem_fun):语法可能会掩盖它们的实用性。
  • 如何使用字符串——以及何时使用它。 (所有弦乐类都有权衡:了解标准弦乐类的优缺点是有教育意义的)。
  • 流和streambufs之间的区别:如何使用前者进行格式化I/O(尝试从流中读取字符串:它并不像应有的那么简单),以及如何使用后者进行低级快速I/O。

用于设计 STL 的原理是在 Boost 库的基础上构建和扩展的。 如果你得到它们,Boost 是可以管理的。 如果您不这样做,并且 Boost 最终很难跟上,您可以返回 STL 来了解方向。

(总的来说,Boost 确实突破了语言的界限。如果您决定真正想要拓展自己的 C++ 知识,并测试您是否真的知道您认为自己知道的内容,那么它可以提供一个有趣的挑战。我使用过 C++十几年来,我教其他人如何使用它,从那时起,我已经熟练掌握了许多高级语言,Boost 仍然让我感到惊讶,它非常有用,但它并不微不足道)。 。

The STL has some core concepts to it. Boost builds on and expands on them. If you understand them, then moving right on to Boost may be of use to you. If not, I would start with the STL.

  • The distinction between the various container types (sequences like vector, list and deque, and associations like map, set and their multi* and unordered_* varieties). Sometimes you can swap one for the other -- sometimes you can't. Know their strengths and their limits.
  • The role of iterators, and how they provide a bridge between containers and algorithms. (This one I find I use over and over).
  • Why there are standard algorithms: they are often tiny amounts of code, so it may not be obvious why they exist. Learn which containers they work with, and how to specialize them for particular cases (for example see how generic copy differs from copy specialized for const char *).
  • How and when traits classes are used.
  • How to use binders (bind1st, ptr_fun and mem_fun): the syntax can obscure their utility.
  • How to use string -- and when not to use it. (All string classes have tradeoffs: learning the pros and cons of the standard one is educational).
  • The difference between streams and streambufs: how to use the former to do formatted I/O (try reading a string from a stream: it's not as straightforward as it should be), and the latter to do low-level fast I/O.

The principles used to design the STL are built upon and expanded on by the Boost libraries. If you get them, Boost is manageable. If you don't, and Boost ends up hard to follow, you can go back to the STL to get your bearings.

(In general Boost really pushes the boundaries of the language. If you decide you want to really push your own knowledge of C++, and test if you really know what you think you know then it can provide an interesting challenge. I've used C++ for more than a dozen years, have taught other people how to use it, have acquired proficiency in many more high-level languages since then and Boost still surprises me. It's very useful, but its not trivial).

浅唱ヾ落雨殇 2024-07-20 20:01:48

我建议在了解 Boost 之前先清楚地了解 STL。 Boost 旨在构建在 STL 之上,许多库最终将成为标准库的一部分。 Boost 库通常不如 STL 成熟且不太标准。 另外,在我看来,许多 boost 库做得太过分了,添加了 C++ 本身不存在的“功能”(导致真正疯狂的语法)。 在许多情况下,有更合理的 C++ 习惯用法可以解决大多数编程问题,而无需使用这些神秘的 Boost 库。

I'd suggest getting a clear handle on STL, before looking at Boost. Boost is meant to build on top of STL and many of the libraries are slated to become part of the standard library eventually. Boost libraries are generally less mature and less standard than STL. Also, many boost libraries go too far, in my opinion, adding "features" that don't natively exist in C++ (leading to really insane syntax). In many cases there are more sane C++ idioms available for solving most programming problems without using these arcane Boost libraries.

纵情客 2024-07-20 20:01:48

我认为从一开始就直接使用两者就可以了。 Boost提供了许多强大的功能,应用广泛,并且拥有良好的声誉。 它提供的大部分内容都与 STL 的设计共享相同的通用编程概念,因此从这个意义上说,它应该不会很令人困惑。

学习某些东西的最好方法是使用优秀的代码,然后去看看它是如何编写的。 这对我来说用 Boost 效果很好。 阅读模板教程,您会受到一小时内发现的新功能的启发。 然后阅读您已经使用过一段时间的 Boost 标题,您将在数周内受到启发。

当然,不要指望立即理解这些内部结构 - 起初我只是使用这些库,而不了解如何构建其中任何一个,这很好。 但在某些时候,你意识到你想写一些具有类似设计的东西,然后你就会去寻找。

如果您采取相反的做法,并将自己限制为“C++ 作为更安全的 C”,那么您就不会接触到所有这些强大的东西,因此您不会那么想查看和理解它们,因此您会编写相当原始的代码并且学习得更慢。

编辑:忘记了我还有另一个想法 - 也看看即将推出的 C++0x 标准。 它融合了许多源自 Boost 的功能。 也就是说,几年后开始学习 C++ 的学生将从一开始就使用这些概念 - 您今天也可以这样做......

I think it's fine to use both straight from the start. Boost provides many powerful features, is widely used, and has a good reputation. Most of the things it provides share the same generic-programming concepts with which the STL was designed, so in that sense it should not be very confusing.

The best way to learn something is to use great code and then go and see how it was written. This worked well for me with Boost. Read a templates tutorial, and you're inspired by the new power you discovered for an hour. Then read a Boost header that you've been using for a bit, and you'll be inspired for weeks.

Of course, don't expect to understand those internals immediately - at first I just used the libraries without understanding how you would build any of that, and that's fine. But at some point you realise you want to write something with a similar design, and then you'll go looking.

If you'd do the opposite, and restrict yourself to "C++ as a safer C", then you wouldn't be exposed to all these powerful things, so you wouldn't be as tempted to look and understand them, and so you would write rather primitive code and learn more slowly.

EDIT: forgot that I had another thought - have a look at the upcoming C++0x standard too. It incorporates many features that originated in Boost. That is, students who start learning C++ a few years from now would be working with these concepts from the very start - you might as well do that today too...

夏夜暖风 2024-07-20 20:01:48

最终,你应该两者都学习。 但是 STL 可以单独学习,而 boost 在理解 STL 之前没有多大意义,因为这就是 Boost 的建模基础,并旨在扩展。 所以学习使用STL作为学习c++的一部分。 然后您可以继续使用 Boost,它或多或少是当今的“第二个标准库”。

Ultimately, you should learn both. But STL can be learned in isolation, whereas boost won't make much sense until you understand the STL, since that's what Boost is modeled on, and designed to extend. So learn to use the STL as part of learning c++. And then you can move on to Boost, which is more or less the "second standard library" these days.

谈下烟灰 2024-07-20 20:01:48

我会先学习STL。

一旦掌握了 C++ 的基础知识,学习如何使用 STL 的各个部分以及它的工作原理将比学习 Boost 更好。 Boost 库倾向于推动 C++ 的优势,尤其是在高度模板化函数的组合中。

我喜欢 Matt Austern 的通用编程和 STL,你可以廉价地二手获得它。

I'd go with learning STL first.

Once you're past the basics with C++, learning how to use parts of STL and then how it works will be better than tackling Boost. The Boost libraries tend to push the edges of C++ especially in combinations of highly-templated functions.

I like Matt Austern's Generic Programming and the STL which you can pickup cheaply secondhand.

鸵鸟症 2024-07-20 20:01:48

这完全取决于您是否能够在所有工作中使用 Boost。 我毫不怀疑会有工作场所禁止它的使用(无论这看起来多么愚蠢)。

但是,如果您认为您可以在任何地方使用它,那么请务必将主要精力集中在它上。

如果 STL 提供了功能,但 Boost 没有提供,请集中精力学习 STL 的那些部分。

It depends entirely on whether you're going to be able to use Boost in all your work. I don't doubt that there'll be workplaces that will forbid its use (however silly that may seem).

But, if you think you'll be able to use it anywhere, then by all means concentrate mostly on it.

If there's functionality provided by the STL but not Boost, concentrate on learning those bits of the STL.

陌生 2024-07-20 20:01:48

首先选择 STL,因为这是您大部分时间都会使用的。 掌握所有的 boost 确实很难,请检查 boost 是否有任何 c++ 开箱即用不可用的库。比如解析库、图形库

First go with STL because that is what you will be using most of the time. Mastering all the boost is really hard, check with boost for any library that is not available with c++ out of box.Like parsing library,graph library

月棠 2024-07-20 20:01:48

通过编程学习并使用最适合的工具。 如果您正在编写需要大量解析的内容,那么您可能会学到一些 boost 精神,但在您达到这一步之前,您还需要了解有关 std::string 和 std::fstream 的知识。 您编写的下一个应用程序可能需要 std::vectors 和 boost::accumulators。

请记住,boost 是巨大的,在你使用它的四分之一之前,你就会成为一名优秀的程序员(就我个人而言,我不希望使用或学习大部分 boost,因为我不需要它...... )。

Learn by programming and use the tools best suited. If you're programming something that needs a lot of parsing then you'll maybe learn some of boost spirit, but before you get that far you'll also have learned stuff about std::string and std::fstream. the next app you write will maybe need std::vectors and boost::accumulators.

Just remember boost is huge, you'll be a good quality programmer way before you've used even a quarter of it (personally I don't expect to ever use or learn most of boost because I don't need it...).

×眷恋的温暖 2024-07-20 20:01:48

先学STL。 如果您从一开始就使用 Boost 学习 C++,那么您以后在不使用 Boost 的工作中将会遇到困难(由于许可原因等)。 首先了解语言标准,然后如果您需要它来完成某些事情,然后使用 Boost 对其进行扩展。

Learn the STL first. If you learn C++ with Boost from the start you will have a hard time later in a job where Boost is not used (because of licensing reasons etc). Know the language standard first, and then expand it with Boost later if you need it for certain things.

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