Are you familiar with imperative versus declarative coding styles? The former is when your code tells the machine how to achieve what you want step by step. The latter is when you tell the machine just what you want to achieve. Certain programming languages favor one over the other. For instance, C is imperative, while SQL is declarative, just like many functional languages. Some languages allow you to mix the styles – think of LINQ in C#.
C++ is a flexible beast that allows you to write code in both ways. Is there one you should prefer? It turns out that when you're writing declarative code, usually a higher level of abstraction is kept, which leads to fewer bugs and easier-to-spot errors. So, how can we write C++ declaratively? There are two main tactics to apply.
The first one is to write functional-style C++, which is where you prefer a pure-functional style (no side effects of functions) if possible. Instead of writing loops by hand, you...