最近打算照着源文档学习C++特性,先从C++11的特性开始。
C++11
C++11是继C++98之后的最重要的更新,也是C++的第二个主要版本。它在标准化实践上和提高C++程序员可用的抽象性上做了大量的变化。
它最终由 ISO 在 2011 年 8 月 12 日之前承认,它曾经被叫做 'C++0x' ,因为它曾被期待在 2010 年之前发布。C++03 到 C++11 中间花了 8 年时间,所以它是迄今为止最长的版本间隔。从此以后, C++ 规则地每 3 年更新一次。
下面这些特性被合并到C++11:
- 来自 TR1:包括TR!的所有除过特殊的函数
- 来自Boost: The thread library, exception_ptr, error_code and error_condition, iterator improvements (begin, end, next, prev)(线程库、exception_ptr、error_code、error_code、改进的迭代器(begin、end、next、prev))
- 来自C:C风格的Unicode转换函数
核心语言特性
- auto and decltype
- defaulted and deleted functions
- final and override
- trailing return type
- rvalue references
- move constructors and move assignment operators
- scoped enums
- constexpr and literal types
- list initialization
- delegating and inherited constructors
- brace-or-equal initializers
- nullptr
- long long
- char16_t and char32_t
- type aliases
- variadic templates
- generalized (non-trivial) unions
- generalized PODs (trivial types and standard-layout types)
- Unicode string literals
- user-defined literals
- attributes
- lambda expressions
- noexcept specifier and noexcept operator
- alignof and alignas
- multithreaded memory model
- thread-local storage
- GC interface (removed in C++23)
- range-for (based on a Boost library)
- static_assert (based on a Boost library)
库特性
头文件
- <array>
- <atomic>
- <cfenv>
- <chrono>
- <cinttypes>
- <condition_variable>
- <cstdint>
- <cuchar>
- <forward_list>
- <future>
- <initializer_list>
- <mutex>
- <random>
- <ratio>
- <regex>
- <scoped_allocator>
- <system_error>
- <thread>
- <tuple>
- <typeindex>
- <type_traits>
- <unordered_map>
- <unordered_set>
库特性
- concurrency support library
emplace()
and other use of rvalue references throughout all parts of the existing library- std::unique_ptr
- std::move_iterator
- std::initializer_list
- stateful and scoped allocators
- std::forward_list
- chrono library
- ratio library
- new algorithms:
- std::all_of, std::any_of, std::none_of,
- std::find_if_not,
- std::copy_if, std::copy_n,
- std::move, std::move_backward,
- std::random_shuffle, std::shuffle,
- std::is_partitioned, std::partition_copy, std::partition_point,
- std::is_sorted, std::is_sorted_until,
- std::is_heap, std::is_heap_until,
- std::minmax, std::minmax_element,
- std::is_permutation,
- std::iota,
- std::uninitialized_copy_n
- Unicode conversion facets
- std::function
- std::exception_ptr
- std::error_code and std::error_condition
- iterator improvements:
缺陷报告
C++11 中修正的缺陷报告(核心 741 个,库 868 个)
编译器支持
主条目: C++ 编译器支持
C++11 核心语言功能特性
C++11 库功能特性