有人让我注意到这篇文章,声称STL术语被误用来指代整个c++标准库,而不是从SGI STL中提取的部分。

(...) it refers to the "STL", despite the fact that very few people still use the STL (which was designed at SGI). Parts of the C++ Standard Library were based on parts of the STL, and it is these parts that many people (including several authors and the notoriously error-ridden cplusplus.com) still refer to as "the STL". However, this is inaccurate; indeed, the C++ standard never mentions "STL", and there are content differences between the two. (...) "STL" is rarely used to refer to the bits of the stdlib that happen to be based on the SGI STL. People think it's the entire standard library. It gets put on CVs. And it is misleading.

我对c++的历史几乎一无所知,所以我无法判断这篇文章的正确性。我应该避免使用STL这个术语吗?或者这只是一个孤立的观点?


当前回答

术语“STL”或“标准模板库”在ISO 14882 c++标准中没有出现。因此,将c++标准库称为STL是错误的。术语“c++标准库”或“标准库”是ISO 14882正式使用的:

ISO 14882 c++标准: 17 -图书馆简介[lib.library]: 本子句描述了c++标准库的内容 一个格式良好的c++程序所使用的 图书馆里,又怎么一个规规矩矩的 实现可以提供 库中的实体。 ...

STL是一个最初由Alexander Stepanov设计的库,独立于c++标准。然而,c++标准库的一些组件包括STL组件,如向量、列表和算法,如复制和交换。

当然,c++标准包含了STL之外的更多东西,所以术语“c++标准库”更正确(并且是标准文档实际使用的)。

其他回答

我最近也提出了同样的观点,但我相信可以容忍一点。如果斯科特·迈耶斯犯了同样的错误,你也有很多同伴。

没有一个答案是正确的。Alexander Stepanov开发了一个名为STL的库(当时为惠普工作)。该库随后被提议包含在c++标准中。

这基本上就是“分叉”开发。委员会包括了一些部分,完全拒绝了其他部分,并重新设计了一些(亚历山大的参与)。原始库的开发后来转移到Silicon Graphics,但与c++标准库分开继续。

在这些片段被添加到标准库之后,标准库的一些其他部分被修改以更好地适应所添加的内容(例如,begin, end, rbegin和rend被添加到std::string中,这样它就可以像容器一样使用)。大约在同一时期,大多数库(甚至是完全不相关的部分)都被制作成模板,以适应不同的类型(例如,标准流)。

有些人也将STL仅仅作为“标准库”的缩写形式使用。

这意味着当有人使用“STL”这个术语时,他们可能指的是六种不同事物中的任何一种。不管是好是坏,大多数使用这个词的人似乎忽略了其含义的多样性,并认为其他人都能认出他们指的是什么。这导致了许多误解,至少有一些严重的口水仗,让大多数参与者看起来很愚蠢,因为他们只是在谈论完全不同的事情。

Unfortunately, the confusion is likely to continue unabated. It's much more convenient to refer to "STL" than something like "the containers, iterators, and algorithms in the C++ standard library, but not including std::string, even though it can act like a container." Even though "C++ standard library" isn't quite as long and clumsy as that, "STL" is still a lot shorter and simpler still. Until or unless somebody invents terms that are more precise (when necessary), and just as convenient, "STL" will continue to be used and confusion will continue to result.

术语“STL”或“标准模板库”在ISO 14882 c++标准中没有出现。因此,将c++标准库称为STL是错误的。术语“c++标准库”或“标准库”是ISO 14882正式使用的:

ISO 14882 c++标准: 17 -图书馆简介[lib.library]: 本子句描述了c++标准库的内容 一个格式良好的c++程序所使用的 图书馆里,又怎么一个规规矩矩的 实现可以提供 库中的实体。 ...

STL是一个最初由Alexander Stepanov设计的库,独立于c++标准。然而,c++标准库的一些组件包括STL组件,如向量、列表和算法,如复制和交换。

当然,c++标准包含了STL之外的更多东西,所以术语“c++标准库”更正确(并且是标准文档实际使用的)。

c++标准库包括c++ STL

c++标准库的内容是:

c++版本的C语言头文件 c++ IO头文件 c++ STL

所以请不要混淆c++标准库和STL。

通俗地说:STL是标准库的一部分。

c++标准库分为:

标准函数库 i / O, -字符串和字符处理, 数学, 时间,日期和本地化, 动态分配, 杂, 宽字符函数 标准OOP和泛型库 -标准c++ I/O类 -字符串类 -数字类 - STL容器类 - STL算法 - STL函数对象 - STL迭代器 - STL分配器 -本地化库 -异常处理类 -杂项支援图书馆

因此,如果你将STL作为标准库来讨论,这是可以的,只要记住STL实现允许泛型,而其他实现则更特定于一种类型。

请参考https://www.tutorialspoint.com/cplusplus/cpp_standard_library.htm