TOC
Important Concepts
Rvalue Reference
Value Category
constexpr
constexpr
vsconst
:constexpr
variables will be evaluated in compile time whileconst
variables may be evaluated in compile time or runtime.- checking with
noexcept
List Initialization
Array declaration
Read array declarations from inside to outside
|
|
size_t
size_t
is a machine-specific unsigned type that is guaranteed to be large enough to hold the size of any object in memory.
Lambda expression
- lambda expression vs inline function
- The
inline
specifier will not guarantee the function call to be inlined.1
- The
auto
Runtime Performance
Type deduction is done in compile time instead of runtime.2
Variable Number of Arguments
initializer_list<T>
1 2 3 4 5 6 7
void foo(initializer_list<int> il) { for(auto x: il) cout << il << " "; return; } foo({1, 2, 3});
ellipsis: no type check being conducted.
Interesting Stuff
Non-const Initialized Array
This is against the ISO standard. But, GCC allows this as an extension by default.
Pros: - convenient when initializing variable length arrays - Reduces memory fragmentation on heap.
Side effects: - Users may be able to overuse stack, causing runtime error.
Stopping Loops Before End
|
|
Syntax Alias
Using A = B
: A will be resolved as B at syntax level, similar to#define
Negative Division
Except for the obscure case where -m overflows, (-m)/n and m/(-n) are always equal to -(m/n), m%(-n) is equal to m%n, and (-m)%n is equal to -(m%n).
|
|