These language features primarily exist to provide some kind of runtime performance benefit, either of memory or of computing speed.
A chronic performance problem with C++03 is the costly and unneeded deep copies that can happen implicitly when objects are passed by value.
Rvalue references can provide performance benefits to existing code without needing to make any changes outside the standard library.
C++11 introduced the keyword constexpr, which allows the user to guarantee that a function or object constructor is a compile-time constant.
The list can be copied once constructed, which is cheap and will act as a copy-by-reference (the class is typically implemented as a pair of begin/end pointers).
The traditional constructor syntax, for example, can look like a function declaration, and steps must be taken to ensure that the compiler's most vexing parse rule will not mistake it for such.
Thus, storing intermediates in variables is difficult, possibly needing knowledge of the internals of a given metaprogramming library.
It will work for C-style arrays, initializer lists, and any type that has begin() and end() functions defined for it that return iterators.
The override special identifier means that the compiler will check the base class(es) to see if there is a virtual function with this exact signature.
The ambiguity inherent in the double meaning of 0 was dealt with in C by using the preprocessor macro NULL, which commonly expands to either ((void*)0) or 0.
However, with nested template declarations, there is a tendency for the programmer to neglect to place a space between the two right angle brackets, thus causing a compiler syntax error.
C++11 improves the specification of the parser so that multiple right angle brackets will be interpreted as closing the template argument list where it is reasonable.
This is a simple example of a union permitted in C++11: The changes will not break any existing code since they only relax current rules.
The first kind, contained within double quotes, produces a null-terminated array of type const char.
The second kind, defined as L"", produces a null-terminated array of type const wchar_t, where wchar_t is a wide-character of undefined size and semantics.
The definition of the type char has been modified to explicitly express that it is at least the size needed to store an eight-bit coding of UTF-8, and large enough to contain any member of the compiler's basic execution character set.
It is also sometimes useful to avoid escaping strings manually, particularly for using literals of XML files, scripting languages, or regular expressions.
This exception is due to the fact that strings have prefixes that affect the specific meaning and type of the characters in question.
An example follows: The assignment statement OutputType some_variable = 1234_mysuffix; executes the code defined by the user-defined literal function.
[20] For example: An attempt to call noInt() with an int parameter will be rejected by the compiler, instead of performing a silent conversion to double.
The declaration assumes this form: Here are some examples of how static_assert can be used: When the constant expression is false the compiler produces an error message.
Attributes can be useful for providing information that, for example, helps the compiler to issue better diagnostics or optimize the generated code.
C++11 offers a number of new language features that the currently existing standard library components can benefit from.
Access is provided, where feasible, to the underlying native thread object(s) for platform-specific operations by the std::thread::native_handle() member function.
To implement reasonably, the TR1 version required an implementation-defined maximum number of contained types, and substantial macro trickery.
Though compilers will have an internal maximum recursion depth for template instantiation (which is normal), the C++11 version of tuples will not expose this value to the user.
Although hash tables are less efficient than a balanced tree in the worst case (in the presence of many collisions), they perform better in many real applications.
Collisions are managed only via linear chaining because the committee didn't consider it to be opportune to standardize solutions of open addressing that introduce quite a lot of intrinsic problems (above all when erasure of elements is admitted).
[25] Here is an example of the use of std::regex_iterator: The library
TR1 introduces, and C++11 adopts, the template class std::result_of that allows one to determine and use the return type of a function object for every declaration.