Chapter 6. Lambda Expressions Flashcards

1
Q

Item 31: Avoid default capture modes.

A

Default by-reference capture can lead to dangling references.

Default by-value capture is susceptible to dangling pointers (especially this), and it misleadingly suggests that lambdas are self-contained.

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

Item 32: Use init capture to move objects into closures.

A

Use C++14’s init capture to move objects into closures.

In C++11, emulate init capture via hand-written classes or std::bind.

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

Item 33: Use decltype on auto&& parameters to std::forward them.

A

Use decltype on auto&& parameters to std::forward them.

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

Item 34: Prefer lambdas to std::bind.

A

Lambdas are more readable, more expressive, and may be more efficient than using std::bind.

In C++11 only, std::bind may be useful for implementing move capture or for binding objects with templatized function call operators.

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