January 2018
Intermediate to advanced
374 pages
9h 53m
English
The introduction of the auto keyword in C++11 has initiated quite a debate among C++ programmers. Many people think it reduces readability, or even that it makes C++ similar to a dynamically typed language. Even if we tend to not participate in those debates, our personal opinion is that you should (almost) always use auto as, in our experience, it makes the code safer and less littered with clutter.
We prefer to use auto for local variables using the left-to-right initialization style. This means that we keep the variable on the left, followed by an equal sign, and then the type on the right side, like this:
auto i = 0;auto x = Foo{};auto y = create_object();auto z = std::mutex{};
With copy elision guarantees introduced ...