第二章:C++重要知识点回顾
C++ primitive types
-
原生数据类型
- char, int, float, double, wchar_t, bool, void, nullptr_t
- 可用numeraic_limits检查范围
- sizeof检查大小Byte
-
数据类型可以有其它的修饰符
- singed, unsigned, long, short
- 限定符:const, restrict
- 存储类型:auto, static , extern, mutable
restrict限制pointer alias
mutable不能修饰const 和 static 类型的变量。
mutable可修饰const函数中的变量
-
Lambda表达式
- 便于定义anonymous匿名,small小,one-time一次性的函数
- [&var1, =var2]
- ->std::vector ,叫作trailing return type
- Lambda表达式组成部分
- Capture clause: []
- Parameter list: ()
- Mutable specification: mutable
- Exception specification: noexcept
- Trailing return type: ->type
- Body: {}
进一步学习:
Effective Modern C++,The C++ Programming Language
Automatic type deduction and decltype
- 自动类型推导
- auto
- decltype()
进一步学习:
Effective Modern C++,The C++ Programming Language
Atomic
-
atomic
- 原子性操作,同于线程保护场景当中
- atomic 模板
- template struct atomic
- template struct atomic <T*>
- 原子性属性限制了编译器一定的优化(比如执行顺序方面)
-
memory model
- 默认:memory_order_seq_cst
- memory_order_relaxed:
- memory_order_consume
- memory_order_acquire
- memory_order_release
- memory_order_seq_cst
nullptr
- NULL 对比nullptr
- NULL 是被定义为整数的
Smarter pointers
- unique_ptr
- shared_ptr