11. (Capture Modes, Brainstorming Question) In Sections 6.5, 6.6 and 6.7 we introduced generic lambda functions, some...

Question:

11. (Capture Modes, Brainstorming Question)

In Sections 6.5, 6.6 and 6.7 we introduced generic lambda functions, some examples and how to deal with captured variables. It is natural to ask which solution is most appropriate in a given context. We have given code examples in this chapter to help you answer the following questions. Of course, a definitive answer can only be given when you actually develop your own applications and make your own conclusions:

a) Compare generic lambdas and template functions with regard to reliability, maintainability and understandability.

b) We can capture by value, by reference, by generalised capture, by local variables and by emulation using std::bind. Give the two best candidates from this list that satisfy the following requirements: maintainability, efficiency, understandability and interoperability with client code.

c) How do the techniques in part

b) scale to larger and more complex code blocks? In which sense are encapsulation and information hiding potentially compromised (if at all) by the introduction of captured variables?

d) As a follow-on to question c), in which circumstances would we prefer to use function objects instead of the other techniques? Would they improve maintainability or efficiency?

e) Is there a need to emulate generalised lambda capture using C++11 and std::bind?
Are there potential benefits?

f) How would you reimplement the code in Section 6.7.1 using a function object?Would it be a better solution?

Fantastic news! We've Found the answer you've been seeking!

Step by Step Answer:

Related Book For  book-img-for-question
Question Posted: