A Brief History Of C++
C++98
C++03
C++03 introduced the first smart pointer as std::auto_ptr, although this was found to contain some serious design flaws, and was deprecated in C++11.
C++03 also introduced the concept of value initialization for automatic objects.
// Pre C++03int any_number; // The value of this could be anything (this is quick)!
// C++03int value_initialized(); // Value is guaranteed to be 0int a[9] = {}; //C++03 was the first C++ version to specify that std::vector must store it’s elements in a contiguous memory space (most implementations already did this, but it was not enforced).
C++11
You could argue that C++ underwent the largest change ever in C++11.
-
C++11introduces the first threading concepts such asstd::threadinto the standard library, largely eliminating the need for using device specific APIs such aspthread(Linux) orCreateThread(Windows). Along withstd::thread, a large number of essential concurrent programming primitives such asstd::mutexandstd::lock_guardwere added. -
C++11also “fixed” thestd::auto_ptrsmart pointer introduced in C++03. As a replacement,C++11introduced thestd::unique_ptr,std::shared_ptrandstd::weak_ptrtypes. -
C++11introduced theautokeyword, which you can use instead of having to specify the full type of a variable, as long as the compiler can work it out from the context surrounding it.// Before C++11std::vector<std::string>* my_var = new std::vector<std::string>();// C++11auto my_var = new std::vector<std::string>();This
autocan save a lot of unnecessary typing, as well as making refactoring easier. -
C++11introduced lambdas to the language. You can now define an anonymous function inside another function, and it can capture local variables from within the context of where it lambda was created (it is important to remember that the lambda will not automatically extend the lifetime of the variables).void my_func() {} -
A new “Python-like” way of creating a for-loop that iterates over a container:
for(auto my_element: my_container) {// Do something} -
C++11introduced initializer lists, which are a way of initializing containers with inline lists:std::vector<int> my_vector = { 0, 1, 2, 3 }; -
C++11was the first version to allow a class constructor to call another constructor belonging to the same class. This is to make code tidier when a class has many constructor signatures and they all share similar base code.
C++14
C++14 was largely an incremental improvement on the features introduced in C++11.
C++17
C++17 introduced the concept of unpacking via { and }.