C++11

C++11 was a major improvement over the previous standard and added many new features to the language to make it easier to read and write, easier to use the standard library.

long long data type

The long long data type is an integer guaranteed to be at least 64 bits in length.

auto keyword

The keyword auto, which did exist already before C++11 but now have a completely new meaning, makes C++11 much easier to read than previous versions. The keyword is used as the type of a variable and tells the compiler that it should determine the type from the type of the value assigned to the variable (see post on auto).

nullptr

In previous versions of C++ (and C) was the literal 0 (zero) both used as a constant integer and a null pointer constant. C++11 defined a new nullptr identifier which is only used to identify a null pointer and cannot be converted to an integer value (see post of nullptr vs NULL).

Lambdas!

Lambdas were introduced in C++11 and completely change how we can write C++. They make using the algorithms defined in the standard library so much easier.

enum class

C++11 defines the new concept enum class which is a strongly typed enum. This is different from a regular enum in the sense that a regular enum is not type safe, they are treated as integers and comparison between enum values is done by the integer values. This means that two values of different enum types will be treated as equal if they have the same integer values. In C++11 are two enum classes not treated as being same if they belong to different enums, even if they have the same integer value.

static_assert

The new static assert keyword makes it possible to verify an assumption of your program at compile time. static_assert takes two arguments, the first is a boolean expression which should be checked and the second is a error message string. The compiler verifies the expression when it is compiling the code and if the expression evaluates to false then the compiler issues an error, stopping the compilation, and displays the error message from the second argument. This can be useful for checking that assumptions that you make on e.g. the size or alignment of a variable is correct.

override identifier

The new identifier override is used to show that a virtual method is overriding a base class method. This makes the code more clear and will help to avoid the common error of accidentally creating a new virtual function in a derived class instead of overriding a base class method. See more in the article on override.

final identifier

The new identifier final is used to stop any derived classes from overriding a virtual function or from stopping users from creating a derived class at all.

The final identifier can also be used to stop anyone from creating a derived class:

delete identifier

The delete identifier is used to remove a function from a class. See the article on deleted functions.

Smart pointers

Now you don’t have an excuse for using new and delete anymore (remember the no naked new rule)! C++11 introduced three smart pointers: std::unique_ptr, std::shared_ptr and std::weak_ptr which takes care of deleting the pointer for you when the object goes out of scope. To make your code more clear prefer to use unique_ptr over shared_ptr since this expresses the ownership of the pointer more clearly.

Range based for

The new range-based for syntax makes it easier than ever to loop through all the items in a container. See the main article on range-based for for more examples.