A parenthesis concerning parentheses
Now that we are here, we have to mention that there were quite a lot of mentions of parenthesis in this chapter. So, we are presenting possibly the most important pair of parentheses you can encounter during the course of this book.
Please look at the following two functions:
static int y; decltype(auto) number(int x) { return y; } decltype(auto) reference(int x) { return (y); }
Those two functions look almost identical, except for the tiny pair of parentheses around the return
value. But the presence of those two parentheses makes the biggest difference. The weird-looking decltype(auto)
introduced in C++14 is a type specifier that combines the functionality of decltype
with automatic type deduction, allowing you to declare a variable with a type that is determined by the expression it is initialized with, while also retaining certain properties of that expression. Unlike auto
, which deduces...