C11 Flashcards
New stuffs
what is copy-and-swap?
To prevent object invalid state when doing copy. In copy constructor, we should do copy original to local variable then do std::swap. std::swap has no throw and use move semetic.
What std function to have mutex object gets unlocked automatically whenever the function is exited – regardless how it is exited.
std::lock_guard
Is it true, compilers, exceptions only affect the performance when thrown?
Yes
What declaration has the ability to bind to anything?
const &&auto
what does std::ref() do?
return reference_wrapper.
auto r = std::ref(x);
what does reference_wrapper do?
to be able to pass object by reference in pass-by-value context. for example: std::bind can take std::ref() to something, transmit it by value and unpacks it back into reference later on.
how to declare “forwarding reference”?
&& auto x = ???
when do we use “forwarding reference”?
when we want to forward variable to other code and don’t care is it const or mutable.
what is purpose of lambda function?
lambda function capability enables programmers to pass functions to regular functions, just as easily as a variable is passed.
How Lambda look like a class?
Lambda is a class with one function. The function is auto operator()
How to do Template specialize for specific argument?
put keyword inline after Template. Templage<> inline
Have fun with cout
operator<<
What is template argument deduction?
Let compiler find the object or function, don’t explicit specify type. Ex Kiki(5442); You can just do Kiki(5442):
Show the easy way to initialize structure data
What does this mean? v
oid test(int*& i);
Read right to left: i is reference of pointer to int.
That is mean we can change i to point to something else and the caller pointer to int will change too.