Wait, no more new? Wtf is auto? constexpr?! Why so many keywords??
What the hell happened with C++ since college?
The good old days of C++98
So, what nobody told me is this, the C++ is an International Standard, and as such, it evolves (gradually and upon many discussions).
What we learn in college is actually a set of rules stablished by the ISO revision of 98 in which we have destructors, templates,
our beloved STL with common containers and algorithms, string, I/O streams, among other things. However, C++ is NOT static
and major changes happened since then, some of them can make you feel it’s not even the same language anymore.
If you are like me and started programming in other languages to follow the tides of the market and now you are trying
to code in C++ again, for fun or business, you may have a hard time with the new concepts that arrived to the language,
let me try to make it easier for you, putting together the information I found useful during my research.
So, what’s changed?
Well… a lot! Kidding, but not kidding Let’s break the main changes into pieces and follow along with a simple sample code,
so in the next sections I’m gonna try to illustrate how the same code would be written in different C++ revisions
introducing the main features of each one.
Our sample code will be a program that reads input from the standard input and outputs a map of word frequency,
ignoring any non-alphabetic character and, by convenience, transforming all characters to lower case.
In C++98 it would look like this:
Fairly simple, right? Moving on…
C++03
This realease is commonly known as a bug fix release for the C++98 revision and included only one new feature,
value initialization, as a side note, when most people refer to
C++98 they are usually refering to C++03.
One valuable addition to the language came in the form of Technical Report 1 (TR1 for short) around 2005.
TR1 is not a standard, it is (as the name says) a technical revision that proposed several additions to the C++ Standard Library, these additions included
smart pointers, hash tables, regular expressions, among others. Many of these additions became part of the C++11 later, but before that happened, vendors started to use
this document as a guide to create extensions, and even though these features weren’t needed to create standard compliant distributions of compilers or libraries, several distributors
implemented them under the namespace std::tr1 to distinguish these features from the then-current standard library.
Let’s make use of these features on our example, still following the standard C++03 but including some of the features in the tr1.
C++11
Most of the changes to the language are credited to this release. It wasn’t only the new features, but the language itself
evolved in a manner that C++11 gave to the programmer a more high-level environment to think and solve problems.
Two of the most significant changes that arrived in C++11 were the move semantics and the rule of 5 (updated version of the rule of 3),
which I am not going to cover here because they are a whole other topic by themselves.
auto
ranged for loops
lambdas
variadic templates
unique_ptr/shared_ptr
constexpr
C++14
Generally speaking, enhancements in the C++11
auto in function return types
generic lambda functions
make_unique/make_shared (new or delete should not be seen in code anymore)
constexpr more flexible
C++17
constexpr support in stdlib
constexpr lambdas
std::string_view
class template argument deduction
fold expressions
structured bindings
if-init expressions
EXTRA: C++20
Future (Feb, 2020), introduces modules, coroutines, std::format, among others.
Coroutines, Modules, Concepts, abbreviated function templates, Ranges, uniform container erasure (std::erase/std::erase_if).
References, credits and things you may want to check out
Hi, I am Carlos, SWE 3x @ Google, 2x @ UNICEF and author of this blog. I like to make things work and hope you enjoy the experiences I am going to share here.