1. C++语言历程
C++语言从1983年正式诞生以来,经历了多次的修订与改版,主要从包含两个大的节点,一是1998年,C++语言正式被C++标准委员会纳入标准,二是2011年,C++语言新增了许多新的特性,大大提升C++语言的实用性。可以把C++标准分成两个大的版本,C++1.0(C++98,C++03,C++03(tr1))和C++2.0(C++11,C++14,C++17,C++20(草案))
C++1.0和2.0的主要特性
| C++版本 | 特性 |
|---|---|
| C++98 | 主要集成在兼容C特性的基础上增加面向对象的特性,包括类、简单继承、内联机制、函数默认参数以及强类型检查,虚函数、函数重载、引用机制(符号为&)、const关键字以及双斜线的单行注释,多重继承、保护成员以及静态成员等特性,并集成了标准模板库STL |
| C++03 | 主要修订C++98中存在的问题 |
| C++03(tr1) | 发布C++希望引入新特性的报告,但没有完全引入,后期加入部分std::tr1相关的功能 |
| C++11 | 新增正则表达式(正则表达式详情)、完备的随机数生成函数库、新的时间相关函数,原子操作支持、标准线程库(2011之前,C和C++语言均缺少对线程的支持)、一种能够和某些语言中foreach语句达到相同效果的新的for语法、auto关键字、新的容器类、更好的union支持、数组初始化列表的支持以及变参模板的支持等等新特性 |
| C++14 | 主要对C++11变准文案描述进行了修正 |
| C++17 | 简化C++语言的日常使用 |
| C++20 | – |
2. 各编译器对C++标准核心功能的支持
| C++11核心功能 | MSVC | GCC | ICC | Clang | 替代方案 |
|---|---|---|---|---|---|
| Rvalue references | 10.0 | 4.3 | 12.0 | 2.9 | Boost.Move |
| Rvalue references for *this | Nov 13 | 4.8.1 | 14.0 | 2.9 | |
| Initialization of class objects by rvalues | 9.0 | 4.3 | 11.1 | 2.9 | |
| Non-static data member initializers | 12.0 | 4.7 | 14.0 | 3.0 | |
| Variadic templates | Nov 12 | 4.3 | 12.1 | 2.9 | |
| Extending variadic template template parameters | Nov 12 | 4.4 | 12.1 | 2.9 | |
| Initializer lists | Nov 12 | 4.4 | 14.0 | 3.1 | |
| Static assertions | 10.0 | 4.3 | 11.1 | 2.9 | Boost.StaticAssert |
| auto-typed variables | 10.0 | 4.4 | 12.0 | 2.9 | Boost.Typeof |
| Multi-declarator auto | 10.0 | 4.4 | 12.0 | 2.9 | Boost.Typeof |
| Removal of auto as a storage-class specifier | 10.0 | 4.4 | 12.0 | 2.9 | Boost.Typeof |
| New function declarator syntax | 10.0 | 4.4 | 12.0 | 2.9 | Boost.ReturnType |
| New wording for C++11 lambdas | 10.0 | 4.5 | 12.0 | 3.1 | Boost.Lambda |
| Declared type of an expression | 10.0 | 4.3 | 12.0 | 2.9 | Boost.Typeof |
| Incomplete return types | 11.0 | 4.8.1 | 12.1 | 3.1 | |
| Right angle brackets | 9.0 | 4.3 | 11.1 | 2.9 | TR1 |
| Default template arguments for function templates | Nov 12 | 4.3 | 12.1 | 2.9 | |
| Solving the SFINAE problem for expressions | No | 4.4 | 12.1 | 2.9 | |
| Template aliases | 12.0 | 4.7 | 12.1 | 3.0 | |
| Extern templates | 9.0 | 4.3 | 11.1 | 2.9 | |
| Null pointer constant | 10.0 | 4.6 | 12.1 | 3.0 | 自己实现的null_ptr |
| Strongly-typed enums | 11.0 | 4.4 | 14.0 | 2.9 | #define |
| Forward declarations for enums | 11.0 | 4.6 | 14.0 | 3.1 | |
| Generalized attributes | 14.0 | 4.8 | 12.1 | 3.3 | |
| Generalized constant expressions | Nov 13 | 4.6 | 14.0 | 3.1 | |
| Alignment support | Nov 13 | 4.8 | No | 3.3 | |
| Delegating constructors | Nov 12 | 4.7 | 14.0 | 3.0 | |
| Inheriting constructors | Nov 13 | 4.8 | 15.0 | 3.3 | |
| Explicit conversion operators | Nov 12 | 4.5 | 14.0 | 3.0 | |
| New character types | 14.0 | 4.4 | 14.0 | 2.9 | |
| Unicode string literals | 14.0 | 4.5 | 14.0 | 3.0 | |
| Raw string literals | Nov 12 | 4.5 | 14.0 | 3.0 | |
| Universal character name literals | 14.0 | 4.5 | 12.1 | 3.1 | |
| User-defined literals | VS14 CTP1 | 4.7 | 15.0 | 3.1 | |
| Standard Layout Types | 11.0 | 4.5 | No | 3.0 | |
| Defaulted and deleted functions | 12.0 | 4.4 | 12.0 | 3.0 | |
| Extended friend declarations | 10.0 | 4.7 | 12.0 | 2.9 | |
| Extending sizeof | Nov 13 | 4.4 | 14.0 | 3.1 | |
| Inline namespaces | 14.0 | 4.4 | 14.0 | 2.9 | |
| Unrestricted unions | 14.0 | 4.6 | 14.0 | 3.1 | |
| Local and unnamed types as template arguments | 9.0 | 4.5 | 12.0 | 2.9 | |
| Range-based for | 11.0 | 4.6 | 13.0 | 3.0 | Boost.Foreach |
| Explicit virtual overrides | 11.0 | 4.7 | 14.0 | 3.0 | #define |
| Minimal support for garbage collection and reachability-based leak detection | 10.0 | No | No | No | |
| Allowing move constructors to throw [noexcept] | Nov 13 | 4.6 | 14.0 | 3.0 | |
| Defining move special member functions | 14.0 | 4.6 | 14.0 | 3.0 | |
| Sequence points | 12.0 | 4.8 | 15.0 | 3.3 | |
| Atomic operations | 11.0 | 4.4 | 13.0 | 3.1 | Boost.Atomic |
| Strong Compare and Exchange | 11.0 | 4.8 | 13.0 | 3.1 | Boost.Atomic |
| Bidirectional Fences | 11.0 | 4.8 | 13.0 | 3.1 | Boost.Atomic |
| Memory model | 12.0 | 4.8 | No | 3.2 | Boost.Atomic |
| Data-dependency ordering: atomics and memory model | 11.0 | 4.8 | No | 3.2 | Boost.Atomic |
| Propagating exceptions | 10.0 | 4.4 | 12.0 | 2.9 | Boost.Exception |
| Abandoning a process and at_quick_exit | 14.0 | 4.8 | No | No | |
| Allow atomics use in signal handlers | 12.0 | 4.8 | No | 3.1 | |
| Thread-local storage | 14.0 | 4.8 | No | 3.3 | Boost.Thread |
| Dynamic initialization and destruction with concurrency | Nov 13 | 4.8 | No | 2.9 | |
| func predefined identifier | Nov 13 | 4.3 | 11.1 | 2.9 | FUNCTION |
| C99 preprocessor | No | 4.3 | 11.1 | 2.9 | |
| long long | 9.0 | 4.3 | 11.1 | 2.9 | __int64 |
| Extended integral types | No | No | No | No |
| C++14核心功能 | MSVC | GCC | ICC | Clang | 替代方案 |
|---|---|---|---|---|---|
| Tweak to certain C++ contextual conversions | 12.0 | 4.9 | 16.0 | 3.4 | |
| Binary literals | 14.0 | 4.9 | 11.0 | 2.9 | |
| Return type deduction for normal functions | Nov 13 | 4.9 | 15.0 | 3.3 | |
| Generalized lambda capture (init-capture) | 14.0 | 4.9 | 15.0 | 3.4 | |
| Generic (polymorphic) lambda expressions | Nov 13 | 4.9 | 16.0 | 3.4 | |
| Variable templates | 15.0 | 5.0 | No | 3.4 | |
| Relaxing requirements on constexpr functions | 15.0 | 5.0 | No | 3.4 | |
| Member initializers and aggregates | 15.0 | 5.0 | 16.0 | 3.3 | |
| Clarifying memory allocation | No | No | No | 3.4 | |
| Sized deallocation | 14.0 | 5.0 | 17.0 | 3.4 | |
| [[deprecated]] attribute | 14.0 | 4.9 | 16.0 | 3.4 | |
| Single-quotation-mark as a digit separator | 14.0 | 4.9 | 16.0 | 3.4 |
| C++17核心功能 | MSVC | GCC | ICC | Clang | 替代方案 |
|---|---|---|---|---|---|
| static_assert with no message | 15.0 | 6 | No | 3.5 | C++11’s static_assert |
| Disabling trigraph expansion by default | 12.0 | 5.1 | No | 3.5 | |
| typename in a template template parameter | 14.0 | 5 | 17.0 | 3.5 | |
| New auto rules for direct-list-initialization | 14.0 | 5 | 17.0 | 3.8 | |
| Fold expressions | No | 6 | No | 3.6 | |
| Attributes for namespaces and enumerators | 14.0 | 6 | No | 3.6 | |
| u8 character literals | 14.0 | 6 | 17.0 | 3.6 | |
| Nested namespace definition | 15.0 | 6 | 17.0 | 3.6 | |
| Allow constant evaluation for all non-type template arguments | No | 6 | No | 3.6 | |
| Remove deprecated register storage class | No | 7 | No | 3.8 | |
| Remove deprecated bool increment | No | 7 | No | 3.8 | |
| Make exception specifications part of the type system | No | 7 | No | No | |
| __has_include in preprocessor conditionals | No | 5 | No | Yes | |
| New specification for inheriting constructors (DR1941 et al) | No | 7 | No | 3.9 | |
| [[fallthrough]] attribute | 15.0 | 7 | No | 3.9 | |
| [[nodiscard]] attribute | No | 7 | No | 3.9 | |
| [[maybe_unused]] attribute | No | 7 | No | 3.9 | |
| Aggregate initialization of classes with base classes | No | 7 | No | 3.9 | |
| constexpr lambda expressions | No | 7 | No | No | |
| Unary Folds and Empty Parameter Packs | No | 6 | No | 3.9 | |
| Differing begin and end types in range-based for | 15.0 | 6 | No | 3.9 | |
| Lambda capture of *this | No | 7 | No | 3.9 | |
| Direct-list-initialization of enums | No | 7 | No | 3.9 | |
| Hexadecimal floating-point literals | No | 3.0 | No | Yes | |
| Using attribute namespaces without repetition | No | 7 | No | 3.9 | |
| Dynamic memory allocation for over-aligned data | No | 7 | No | No | |
| Template argument deduction for class templates | No | 7 | No | No | |
| Non-type template parameters with auto type | No | 7 | No | No | |
| Guaranteed copy elision | No | 7 | No | No | |
| Stricter expression evaluation order | No | 7 | No | No | |
| Requirement to ignore unknown attributes | No | Yes | No | Yes | |
| constexpr if-statements | No | 7 | No | 3.9 | |
| Inline variables | No | 7 | No | 3.9 | |
| Structured bindings | No | 7 | No | No | |
| Separate variable and condition for if and switch | No | 7 | No | 3.9 | |
| Matching template template parameters to compatible arguments | No | 7 | No | No | |
| Removing deprecated dynamic exception specifications | No | 7 | No | No | |
| Pack expansions in using-declarations | No | No | No | No |
附:经典网站及书籍
| 名称 | 说明 |
|---|---|
| C++14标准PDF | https://doc.imzlp.me/viewer.html?file=docs/standard/isocpp2014.pdf |
| C++11标准PDF | https://doc.imzlp.me/viewer.html?file=docs/standard/isoc11.pdf |
| 多种编译器对C++11的支持 | http://www.klayge.org/wiki/index.php/多种编译器对C%2B%2B11的支持 |
| 多种编译器对C++14的支持 | http://www.klayge.org/wiki/index.php/多种编译器对C%2B%2B14的支持 |
| 多种编译器对C++17的支持 | http://www.klayge.org/wiki/index.php/多种编译器对C%2B%2B17的支持 |
| 在线开发环境 | https://wandbox.org/ |