Open rainit2006 opened 5 years ago
C++11/14/17 の機能のサポート (Modern C++) https://msdn.microsoft.com/ja-jp/library/hh567368.aspx 可以认为VS2015之后,对C++11基本都支持了。
C++11 C++11是曾经被叫做C++0x,是对目前C++语言的扩展和修正,C++11不仅包含核心语言的新机能,而且扩展了C++的标准程序库(STL),并入了大部分的C++ Technical Report 1(TR1)程序库(数学的特殊函数除外)。 C++11包括大量的新特性:包括lambda表达式,类型推导关键字auto、decltype,和模板的大量改进。
从 C++11 开始,被弃用的主要特性: https://changkun.de/modern-cpp/book/01-intro/index.html 注意:弃用并非彻底不能用,只是用于暗示程序员这些特性将从未来的标准中消失,应该尽量避免使用。但是,已弃用的特性依然是标准库的一部分,并且出于兼容性的考虑,大部分特性其实会『永久』保留。
// C++98
map<int, string>::iterator i = m.begin();
double const xlimit = config["xlimit"];
singleton& s = singleton::instance();
// C++11 auto i = begin(m); auto const xlimit = config["xlimit"]; auto& s = singleton::instance();
- 使用shared_ptr明确共享所有权。更喜欢使用make_shared来有效的创建共享对象。
// C++98 widget* pw = new widget(); ... delete pw;
// C++11
auto pw = make_shared
- nullptr
始终使用nullptr作为空指针的值,绝不使用模棱两可的字面量0或者NULL宏,因为它们可以是一个整形或指针。
// C++98 int* p = 0;
// C++11 int* p = nullptr;
- 初始化
int n {4};
string s{"Hello"}
vector
C++ 11
initializer list
C++11提供的新类型,定义在
static std::map<string, string> const nameToBirthday = {
{"lisi", "18841011"},
{"zhangsan", "18850123"},
{"wangwu", "18870908"},
{"zhaoliu", "18810316"},
};
统一初始化(uniform intialization) 在C++ 11之前,所有对象的初始化方式是不同的,经常让写代码的我们感到困惑。C++ 11努力创造一个统一的初始化方式。其语法是使用{}和std::initializer_list。
auto type
foreach
nullptr
enum class
delegation constructor
override (for virtual function)
final (for virtual function and class)
Compiler generated defualt constructor
delete
constexpr 关键字constexpr 是C++11中引入的关键字,声明为constexpr类型的变量,编译器会验证该变量的值是否是一个常量表达式。
constexpr A(){return 3;}
int arr[A()+2];
new string literals
lambda function