cpp11

C++11 Overview

C++11: Purpose of this FAQ section

The purpose of this FAQ’s C++11 sections (including this section) is:

  • To give an overview of the new facilities (language features and standard libraries) offered by C++11 in addition to what is provided by the previous version of the ISO C++ standard.
  • To give an idea of the aims of the ISO C++ standards effort.
  • To present a user’s view of the new facilities
  • To provide references to allow for a more in depth study of features.
  • To name many of the individuals who contributed (mostly as authors of the reports they wrote for the committee). The standard is not written by a faceless organization.

We often borrow examples from the proposals. In those cases: Thanks to the proposal authors. Many other examples are borrowed from Stroustrup’s talks and papers.

Please note that the purpose of this FAQ is not to provide comprehensive discussion of individual features or a detailed explanation of how to use them. The aim is to give simple examples to demonstrate what C++11 has to offer (plus references). Our ideal is “max one page per feature” independently of how complex a feature is. Details can often be found in the references.

See the FAQ Home page for a list of all C++11 sections.

What is C++11?

C++11 is the ISO C++ standard formally ratified by a 21-0 national vote in August 2011. This public working paper is the January 2012 working draft, and contains the C++11 standard plus minor editorial changes.

C++11 is a major upgrade over C++98/03, with performance and convenience features that make it feel like a new language.

The previous (and first) standard is often referred to as C++98 or C++03; the differences between C++98 and C++03 are so few and so technical that they ought not concern users. This FAQ discusses changes between C++98/C++03 to C++11.

What is C++0x?

The “under-development” name for C++11. Before its official ratification in 2011, the then-under-development standard was unofficially called C++0x, as it was hoped to be completed in C++08 or C++09. Think of ‘x’ as hexadecimal (i.e., C++0B == C++11).

When will compilers implement C++11?

Currently shipping compilers (e.g. GCC C++, Clang C++, IBM C++, and Microsoft C++) already implement most or all C++11 features, and are working on C++14 features.

Modulo bugs, the first fully conforming C++11 language implementation was GCC 4.8.1 (May 31, 2013) but it still did not have a conforming standard library. The first complete C++11 implementation, including both the language and the standard library, was Clang 3.3 (June 5, 2013).

Here are links to C++11 information from purveyors:

How did the committee approach picking new language and library features for C++11?

You don’t improve a language by simply adding every feature that someone considers a good idea. In fact, essentially every feature of most modern languages has been suggested for C++ by someone: Try to imagine what the union of C99, C#, Java, Haskell, Lisp, Python, and Ada would look like. To make the problem more difficult, remember that it is not feasible to eliminate older features, even in the reasonably rare cases when the committee agrees that they are bad: Experience shows that users force every implementer to keep providing deprecated and banned features under compatibility switches (or by default) for decades.

In addition to the general design goals, to try to select rationally from the flood of suggestions the committee devised a set of specific design goals. The result has been a language with greatly improved abstraction mechanisms. The range of abstractions that C++ can express elegantly, flexibly, and at zero cost compared to hand-crafted specialized code has greatly increased. When we say “abstraction” people often just think “classes” or “objects.” C++11 goes far beyond that: The range of user-defined types that can be cleanly and safely expressed has grown with the addition of features such as initializer-lists, uniform initialization, template aliases, rvalue references, defaulted and deleted functions, and variadic templates. Their implementation eased with features, such as auto, inherited constructors, and decltype. These enhancements are sufficient to make C++11 feel like a new language.

For information about accepted language features, see the C++11 language extensions sections of this FAQ, listed on the FAQ Home page.

The standard library definition is already about 70% of the normative text of the standard (and that doesn’t count the C standard library, which is included by reference). Even though some members would have liked to see many more standard libraries, nobody could claim that the Library Working Group has been lazy. It is also worth noting that the C++98 libraries have been significantly improved through the use of new language features, such as initializer-lists, rvalue references, variadic templates, noexcept, and constexpr. The C++11 standard library is easier to use and provides better performance than the C++98 one.

For information about accepted library features, see the C++11 library extensions sections of this FAQ, listed on the FAQ Home page.

What were the general design goals of the C++11 effort?

C++ has from its inception been a general-purpose programming language with a bias towards systems programming that

The overall aims of the C++11 effort was to strengthen that:

  • Make C++ a better language for systems programming and library building – that is, to build directly on C++’s contributions to programming, rather than providing specialized facilities for a particular sub-community (e.g. numeric computation or Windows-style application development).
  • Make C++ easier to teach and learn – through increased uniformity, stronger guarantees, and facilities supportive of novices (there will always be more novices than experts).
  • Naturally, this is done under very stringent compatibility constraints. Only very rarely is the committee willing to break standards conforming code, though that’s done when a new keyword (e.g. static_assert, nullptr, and constexpr) is introduced.

For more details see:

What specific design goals guided the committee?

Naturally, different people and different organizations involved with the standardization have somewhat different aims, especially when it comes to details and to priorities. Also, detailed aims change over time. Please remember that the committee can’t even do all that everyone agrees would be good things – it consists of volunteers with very limited resources. However, here are a set of criteria that has seen real use in the discussion of which features and libraries were appropriate for C++11:

  • Maintain stability and compatibility – don’t break old code, and if you absolutely must, don’t break it quietly.
  • Prefer libraries to language extensions – an ideal at which the committee wasn’t all that successful; too many people in the committee and elsewhere prefer “real language features.”
  • Prefer generality to specialization – focus on improving the abstraction mechanisms (classes, templates, etc.).
  • Support both experts and novices – novices can be helped by better libraries and through more general rules; experts need general and efficient features.
  • Increase type safety – primarily though facilities that allow programmers to avoid type-unsafe features.
  • Improve performance and ability to work directly with hardware – make C++ even better for embedded systems programming and high-performance computation.
  • Fit into the real world – consider tool chains, implementation cost, transition problems, ABI issues, teaching and learning, etc.

Note that integrating features (new and old) to work in combination is the key – and most of the work. The whole is much more than the simple sum of its parts.

Another way of looking at detailed aims is to look at areas of use and styles of usage:

  • Machine model and concurrency – provide stronger guarantees for and better facilities for using modern hardware (e.g. multicores and weakly coherent memory models). Examples are threads, futures, thread-local storage, and atomics.
  • Generic programming – GP is among the great success stories of C++98; we needed to improve support for it based on experience. Examples are auto and template aliases.
  • Systems programming – improve the support for close-to-the-hardware programming (e.g. low-level embedded systems programming) and efficiency. Examples are constexpr, std::array, and generalized PODs.
  • Library building – remove limitations, inefficiencies, and irregularities from the abstraction mechanisms. Examples are inline namespace, inherited constructors, and rvalue references.

Where can I find the committee papers for C++11 features?

Go to the committee papers archive and focus mainly on 2005 through early 2011. There you will most likely drown in details. Look for “issues lists” and “State of” (e.g. State of Evolution (July 2008)) lists. The key groups then active were

  • Core (CWG) – dealing with language-technical issues and formulation
  • Evolution (EWG) – dealing with language feature proposals and issues crossing the language/library boundary
  • Library (LWG) – dealing with library facility proposals

Where can I find academic and technical papers about C++11?

Here is an incomplete list. To suggest additions or corrections, use the Suggestion icon on this FAQ heading (you can do that on any FAQ of course).

Where else can I read about C++11?

The amount of information about C++11 is increasing as most C++ implementations provide the new language features and libraries. Here is a short list of sources:

Are there any videos about C++11?

Yes:

Is C++11 hard to learn?

C++11 makes C++ easier to learn than ever, and has near-perfect compatibility with C++98/03.

For those who have never used C++, C++11 is far easier to learn than the previous version of the language. Even though there are more features, the code you write tends to be simpler and many things that used to be hard or obscure aren’t any more. (Of course, like any general-purpose language, there are still some hard or obscure parts.) In fact, Stroustrup now covers the essentials of the entire C++11 language and library in one concise 180-page book, A Tour of C++.

If you know C++98/03, essentially all your code will continue to work unchanged because C++11 is nearly perfectly backward-compatible with the previous standard. However, as you learn the new features, you will find that they often make your code simpler (e.g., auto), clearer (e.g., template aliases instead of typedef), more powerful and expressive (e.g., lambda functions), and faster than ever (e.g., rvalue references and move semantics will often make your existing C++ code faster simply by recompiling it with a C++11 compiler!). The extra simplicity and clarity really make C++11 feel like a fresh new language.

Clearly C++11 is bigger than C++98 and has more features. So how can it be easier to learn? When designing C++11, the committee used several tools for simplification (from the point of view of learners), including:

  • Generalization: In some cases C++11 replaces, say, three rules with one more general rule (e.g., uniform initialization, inheriting constructors, and threads). It also removes special cases so there’s less to learn (as a trivial example, vector<vector<int>> is perfectly legal now without putting a space between >>). All of this reduces “concept count” or the number of things to memorize by rote; for example, a rule with three exceptions or special cases has a concept count of four things to memorize, whereas two general rules that just work together in all combinations have a concept count of just two things to memorize, yet can often express much more than the single rule with three special cases.
  • Simpler alternatives: In other cases C++11 provides new facilities that are easier to use than their older alternatives (e.g., std::array, auto, range-for statement, and regex).

A word of caution: People who insist on teaching C++ “from the bottom up” (corner cases first, C subset first, etc.) will nullify any such advantage and make the language appear obscure and hard. This is not necessary or desirable. We are finally getting better materials that teach C++ from the top down, notably Stroustrup’s A Tour of C++. If you see people learning C++ from the bottom up, steer them to the Tour and similar materials as quickly as possible.

Is C++11 the final C++ standard?

No. The upcoming next C++ International Standard is called C++14 as it is expected to be published in 2014, and as of this writing it is nearly finalized. The committee is also working on issuing numerous Technical Specifications due in 2014 onward, on topics from low-level libraries like File System and Networking to Concurrency and Parallelism and Concepts, and more. Many of these Technical Specifications are expected to become part of the next major actual C++ International Standard, currently expected in about 2017.

For the latest details, see the current status page.