Top 5 favorite modern C++ features

I must say, when I first started dabbling in computer programming, C++ was not at all my first choice of language. The general perception of C++ that I got from my friends and from forums were like…

C++ is a language for really, really smart people.
Each line of code is about 30-40 characters long on average, if not longer.
Everything is needlessly difficult and fraught with pitfalls.
There are so many *, #, &, <>, (), {}, /, [ ], <<, ::, and ! symbols everywhere that it looks like comic book characters swearing.
Before you even think of attempting C++, you should first know C well.
It is impossible to know the whole language. Even people who have been learning it for 15 years have barely even scratched the surface of what is possible.
Template metaprogramming is the devil.

Looking back on these statements today, as someone who now programs mostly in C++ for fun, I see a grain of truth in each of them. C++ is certainly not perfect. Far from it; it is a flawed, verbose, error-prone, needlessly complicated, sometimes rage-inducing language.

But why do I write in it, then, if it’s so terrible? And why for fun? Well, I probably would have never picked up C++ in the first place if the ISO C++11 standard hadn’t come out.

At the time, I was playing around with straight C for a while since I moved to Linux, though with time I found it to be a little too spartan for my taste. I was interested in learning C++ to make games since many well-known game frameworks use the language natively, and I wanted to carry over my C knowledge.

Originally dubbed “C++0x” before delayed to 2011, the C++11 standard added a ton of new and attractive features which attracted people like me, who were previously used to C#, Java, Go, Ruby, Python, etc. Due to extremely positive reception in the C++ community, the ISO committee has been hard at work creating the C++14 standard, and the up-and-coming C++17 standard. These last few iterations have been made such radical changes to the core language that they are colloquially referred to as “modern C++.”

C++11 feels like a new language. I write code differently now than I did in C++98. The C++11 code is shorter, simpler, and usually more efficient than what I used to write.

— Bjarne Stroustrup, creator of C++, https://isocpp.org/tour

These features made me comfortable enough to dive into C++, though they are not necessarily the reasons why I decided to stay. I stayed because I could now work almost as efficiently as I could in C# or Java, but at the same time I had the gory insides of the machine exposed to me. That’s right, I actually found it refreshing to see why the computer behaved the way it did, and not only that, I loved the fact that I could drop the fancy object-oriented stuff and fall back to glorious old C if I ever needed to. C++ also blew my mind several times over in regards to what I thought was possible to get computer programs to do (I’m looking at you, template metaprogramming).

So grab a beverage and some popcorn, because here come my top 5 favorite “modern C++” features.

Read more