January 2018
Intermediate to advanced
374 pages
9h 53m
English
Take a look at this code snippet, which concatenates two strings and compares the result:
auto func_a() {
auto a = std::string{"Cole"};
auto b = std::string{"Porter"};
auto c = std::string{"ColePorter"};
auto is_cole_porter = (a + b) == c;
// is_cole_porter is true
}
Here is a visual representation of the preceding code snippet:

The problem, here, is that (a + b) constructs a new temporary string in order to compare it with c. Instead of constructing a new string, we could just compare the concatenation right away, like this:
auto is_concat_equal( const ...