STL初认识

2019-03-27  本文已影响0人  Little熊猫

一 C++ 与STL 历史

STL全称standard template library,由Alexander Stepanov于1979年创建,也是Bjarne Stroustrup创造C++的年代。STL与C++有一样长的历史。STL先以C完成,后再以C++完成。STL从1993年9月与C++标准委员会的第一次接触,到1998年9月定案的C++标准规格中C++标准程序库的一个大脉系。STL也有很多历史版本,最著名的有如下几个版本

Original STL implementation by Stepanov and Lee. 1994, Hewlett-Packard. No longer maintained.
SGI STL, based on original implementation by Stepanov & Lee. 1997, Silicon Graphics. No longer maintained.
libstdc++ by the GNU Project (was part of libg++)[13]
libc++ from LLVM
STLPort, based on SGI STL
Rogue Wave Standard Library (HP, SGI, SunSoft, Siemens-Nixdorf)
Dinkum STL library by P.J. Plauger
The Microsoft STL which ships with Visual C++ is a licensed derivative of Dinkum's STL.
Apache C++ Standard Library (The starting point for this library was the 2005 version of the Rogue Wave standard library[14])
EASTL, developed by Paul Pedriana at Electronic Arts and published as part of EA Open Source.

平时接触较多的是GNU的libstdc++和LLVM中的libc++,微软的STL

二 libc++ VS libstdc++

android开始使用libstdc++后来切换成libc++,libc++和libstdc++他们之间的差异主要有如下:

From years of experience (including having implemented the standard library before), we've learned many things about implementing the standard containers which require ABI breakage and fundamental changes to how they are implemented. For example, it is generally accepted that building std::string using the "short string optimization" instead of using Copy On Write (COW) is a superior approach for multicore machines (particularly in C++11, which has rvalue references). Breaking ABI compatibility with old versions of the library was determined to be critical to achieving the performance goals of libc++.

Mainline libstdc++ has switched to GPL3, a license which the developers of libc++ cannot use. libstdc++ 4.2 (the last GPL2 version) could be independently extended to support C++11, but this would be a fork of the codebase (which is often seen as worse for a project than starting a new independent one). Another problem with libstdc++ is that it is tightly integrated with G++ development, tending to be tied fairly closely to the matching version of G++.

STLport and the Apache libstdcxx library are two other popular candidates, but both lack C++11 support. Our experience (and the experience of libstdc++ developers) is that adding support for C++11 (in particular rvalue references and move-only types) requires changes to almost every class and function, essentially amounting to a rewrite. Faced with a rewrite, we decided to start from scratch and evaluate every design decision from first principles based on experience.

Further, both projects are apparently abandoned: STLport 5.2.1 was released in Oct'08, and STDCXX 4.2.1 in May'08.

总结起来就是1) abi breakage 2)GPL3 licensen 3)特性跟随g++ 4)STLport和APache libstdcxx缺少C++11的支持,基于上面几个原因libc++被创造出来

三 C++标准版本

C++的几个标准的版本
Year C++ Standard Informal name
1998 ISO/IEC 14882:1998[23] C++98
2003 ISO/IEC 14882:2003[24] C++03
2011 ISO/IEC 14882:2011[25] C++11, C++0x
2014 ISO/IEC 14882:2014[26] C++14, C++1y
2017 ISO/IEC 14882:2017[9] C++17, C++1z
2020 to be determined
比如我们在编译中使用的g++ std=c++11,使用C++11版本, clang则使用参数-std=c++11

上一篇下一篇

猜你喜欢

热点阅读