C11 Flashcards

New stuffs

1
Q

what is copy-and-swap?

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

What std function to have mutex object gets unlocked automatically whenever the function is exited – regardless how it is exited.

A

std::lock_guard

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

Is it true, compilers, exceptions only affect the performance when thrown?

A

Yes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What declaration has the ability to bind to anything?

A

const &&auto

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

what does std::ref() do?

A

return reference_wrapper.

auto r = std::ref(x);

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

what does reference_wrapper do?

A

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 well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

how to declare “forwarding reference”?

A

&& auto x = ???

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

when do we use “forwarding reference”?

A

when we want to forward variable to other code and don’t care is it const or mutable.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

what is purpose of lambda function?

A

lambda function capability enables programmers to pass functions to regular functions, just as easily as a variable is passed.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q

How Lambda look like a class?

A

Lambda is a class with one function. The function is auto operator()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

How to do Template specialize for specific argument?

A

put keyword inline after Template. Templage<> inline

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q

Have fun with cout

A

operator<<

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What is template argument deduction?

A

Let compiler find the object or function, don’t explicit specify type. Ex Kiki(5442); You can just do Kiki(5442):

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

Show the easy way to initialize structure data

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does this mean? v

oid test(int*& i);

A

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.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
16
Q

What is raw string literals?

A

string that escape char of c++ are not processed.

R”( and end with )”

Example:

string str1( R”(we can have \n and \t)”);

cout << str1 << endl;

output is

we can have \n and \t

17
Q
A