August 2012
Intermediate to advanced
976 pages
30h 17m
English
constexpr FunctionsIn § 6.3.2 (p. 224) we wrote a small function that returned a reference to the shorter of its two string parameters. The benefits of defining a function for such a small operation include the following:
• It is easier to read and understand a call to shorterString than it would be to read and understand the equivalent conditional expression.
• Using a function ensures uniform behavior. Each test is guaranteed to be done the same way.
• If we need to change the computation, it is easier to change the function than to find and change every occurrence of the equivalent expression.
• The function can be reused rather than rewritten for other applications.
There is, however, one potential drawback to making
Read now
Unlock full access