C++11 - the new ISO C++ standard

http://www.stroustrup.com/C++11FAQ.html

https://docs.microsoft.com/en-us/cpp/cpp/welcome-back-to-cpp-modern-cpp?redirectedfrom=MSDN&view=vs-2019

https://github.com/changkun/modern-cpp-tutorial

https://changkun.gitbooks.io/cpp1x-tutorial/content/

C++11 - the new ISO C++ standard

Modified August 19, 2016

This document is written by and maintained by Bjarne Stroustrup. Constructive comments, corrections, references, and suggestions are of course most welcome. Currently, I'm working to improve completeness and clean up the references.

Translations:

I have contributed to the new, unified, isocpp.org C++ FAQ maintained by The C++ Foundation of which I am a director. The maintenance of this FAQ is likely to become increasingly sporatic.

C++11 is the ISO C++ standard ratified in 2011. The previous 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.

A late working paper is available. This is close to the final draft international standard formally accepted by a 21-0 national vote in August 2011.

Before its official ratification, we called the upcoming standard C++0x. I have not had the time to update the name consistently, sorry, and anyway I like the name C++0x :-). The name "C++0x" is a relict of the days where I and others, hoped for a C++08 or C++09. Think of 'x' as hexadecimal (i.e., C++0B == C++11).

All official documents relating to C++11/C++0x can be found at the ISO C++ committee's website. The official name of the committee is SC22 WG21.

Caveat: This FAQ will be under construction for quite a while. Comments, questions, references, corrections, and suggestions welcome.

 


Purpose

The purpose of this C++11 FAQ 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.

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). My ideal is "max one page per feature" independently of how complex a feature is. Details can often be found in the references.

 


Lists of questions

Here are some high-level questions

Questions about individual language features can be found here:

I often borrow examples from the proposals. In those cases: Thanks to the proposal authors. Many of the examples are borrowed from my own talks and papers.

Questions about individual standard library facilities can be found here:

Below are answers to specific questions as indexed above.

 


What do you think of C++11?

That's a (to me) amazingly frequent question. It may be the most frequently asked question. Surprisingly, C++11 feels like a new language: The pieces just fit together better than they used to and I find a higher-level style of programming more natural than before and as efficient as ever. If you timidly approach C++ as just a better C or as an object-oriented language, you are going to miss the point. The abstractions are simply more flexible and affordable than before. Rely on the old mantra: If you think of it as a separate idea or object, represent it directly in the program; model real-world objects, and abstractions directly in code. It's easier now: Your ideas will map to enumerations, objects, classes (e.g. control of defaults), class hierarchies (e.g. inherited constructors), templates, aliases, exceptions, loopsthreads, etc., rather than to a single "one size fits all" abstraction mechanism.

My ideal is to use programming language facilities to help programmers think differently about system design and implementation. I think C++11 can do that - and do it not just for C++ programmers but for programmers used to a variety of modern programming languages in the general and very broad area of systems programming.

In other words, I'm still an optimist.

 


When will C++11 be a formal standard?

It is now! The first draft for formal comments was produced in September 2008. The Final International Draft standard (FCD) unanimously approved by the ISO C++ committee on March 25, 2011. It was formally approved by a 21-0 national vote in August 2011. The standard was published this year (2011).

Following convention, the new standard is called C++11 (because it was published in 2011). Personally, I prefer plain C++ and to use a year marker only when I need to distinguish it from previous versions of C++, such as ARM C++, C++98 and C++03. For a transition period, I still use C++0x in places. Think of 'x' as hexadecimal.

 


When will compilers implement C++11?

Currently shipping compilers (e.g. GCC C++, Clang C++,IBM C++, and Microsoft C++) already implement many C++11 features. For example, it seems obvious and popular to ship all or most of the new standard libraries.

I expect more and more features to become available with each new release. I expect to see the first complete C++11 compiler sometime in 2012, but I do not care to guess when such a compiler ships or when every compiler will provide all of C++11. I note that every C++11 feature has already been implemented by someone somewhere so there is implementation experience available for implementers to rely on.

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

 


When will the new standard libraries be available?

Initial versions of the new standard libraries are currently shipping with the GCC, Clang and Microsoft implementations, and are available from boost.

 


What new language features does C++11 provide?

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 to me for C++ by someone: Try to imagine what the superset 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 if 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.

To try to select rationally from the flood of suggestions we devised a set of specific design aims. We couldn't completely follow them and they weren't sufficiently complete to guide the committee in every detail (and IMO couldn't possible be that complete).

The result has been a language with greatly improved abstraction mechanisms. The range of abstractions that C++ can express elegantly, flexibly, and at zero costs 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-listsuniform initializationtemplate aliasesrvalue referencesdefaulted and deleted functions, and variadic templates. Their implementation eased with features, such as autoinherited constructors, and decltype. These enhancements are sufficient to make C++11 feel like a new language.

For a list of accepted language features, see the feature list

 


What new standard libraries does C++11 provide?

I would have liked to see more standard libraries. However, note that 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 of us 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-listsrvalue referencesvariadic templatesnoexcept, and constexpr. The C++11 standard library is easier to use and provides better performance that the C++98 one.

For a list of accepted libraries, see the library component list.

 


What were the aims of the C++11 effort?

C++ is a general-purpose programming language with a bias towards systems programming that

  • is a better C
  • supports data abstraction
  • supports object-oriented programming
  • supports generic programming

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_assertnullptr, and constexpr) is introduced.

For more details see:

 


What specific design aims 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 the thread ABIfuturesthread-local storage, and the atomics ABI.
  • 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 constexprstd::array, and generalized PODs.
  • Library building -- remove limitations, inefficiencies, and irregularities from the abstraction mechanisms. Examples are inline namespaceinherited constructors, and rvalue references.

 


Where can I find the committee papers?

Go to the papers section of the committee's website. 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 are

  • 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

Here is the latest draft C++11 standard.

 


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

This list is likely to be incomplete -- and likely to frequently go out of date as people write new papers. If you find a paper that ought to be here and is not, please send it. Also, not all papers will be completely up-to-date with the latest improvements of the standard. I'll try to keep comments current.

 


Where else can I read about C++11?

The amount of information about C++11 is increasing as the standard nears completion and C++ implementations start providing new language features and libraries. Here is a short list of sources:

 


Are there any videos about C++11?

(To people who know me, this is a proof that this really is an FAQ, rather than a series of my own favorite questions; I'm not a fan of videos on technical topics -- I find the video distracting and the verbal format too likely to contain minor technical errors).

Yes:

 


Is C++11 hard to learn?

Well, since we can't remove any significant features from C++ without breaking large amounts of code, C++11 is larger than C++98, so if you want to know every rule, learning C++11 will be harder. This leaves us with just two tools for simplification (from the point of view of learners):

Obviously, a "bottom up" teaching/learning style will nullify any such advantage, and there are currently (obviously) very little material that takes a different approach. That ought to change with time.

 


How does the committee operate?

The ISO Standards committee, SC22 WG21, operates under the ISO rules for such committees. Curiously enough, these rules are not standardized and change over time.

Many countries have national standards bodies with active C++ groups. These groups hold meetings, coordinate over the web, and some send representatives to the ISO meetings. Canada, France, Germany, Switzerland, UK, and USA are present at most meetings. Denmark, the Netherlands, Japan, Norway, Spain, and others are represented in person less frequently.

Much of the work goes on in-between meetings over the web and the results are recorded as numbered committee papers on the WG21 website.

The committee meets two to three times a year for a week each time. Most work at those meetings are in sub-working groups, such as "Core", "Library", "Evolution", and "Concurrency." As needed, there are also in-between meetings of ad-hoc working groups on specific urgent topics, such as "concepts" and "memory model." Voting takes place at the main meetings. First, working groups hold "straw votes" to see if an issue is ready for presentation to the committee as a whole. Then, the committee as a whole votes (one member one vote) and if something is accepted the nations vote. We take great care that we do not get into a situation where the majority present and the nations disagrees -- proceeding if that is the case would guarantee long-term controversy. Final votes on official drafts are done by mail by the national standards bodies.

The committee has formal liaison with the C standards group (SC22 WG14) and POSIX, and more or less formal contacts with several other groups.

 


Who is on the committee?

The committee consists of a large number of people (about 250) out of whom 90+ turn up at the week-long meetings two or three times a year. In addition there are national standards groups and meetings in several countries. Most members contribute either by attending meetings, by taking part in email discussions, or by submitting papers for committee consideration. Most members have friends and colleagues who help them. From day #1, the committee has had members from many countries and at every meeting people from half a dozen to a dozen countries attend. The final votes are done by about 20 national standards bodies. Thus, the ISO C++ standardization is a fairly massive effort, not a small coherent group of people working to create a perfect language for "people just like themselves." The standard is what this group of volunteers can agree on as being the best they can produce that all can live with.

Naturally, many (but not all) of these volunteers have day jobs focused on C++: We have compiler writers, tool builders, library writers, application builders (too few of those), researchers (only a few), consultants, test-suite builders, and more.

Here is a very abbreviated list of organizations involved: Adobe, Apple, Boost, Bloomberg, EDG, Google, HP, IBM, Intel, Microsoft, Red Hat, Sun.

Here is a short list of names of members who you may have encountered in the literature or on the web: Dave AbrahamsMatt AusternPete BeckerHans BoehmSteve ClamageLawrence CrowlBeman DawesFrancis GlassborowDoug GregorPablo HalpernHoward HinnantJaakko JarviJohn Lakos, Alisdair Meredith, Jens Maurer, Jason Merrill, Sean ParentP.J. PlaugerTom PlumGabriel Dos ReisBjarne StroustrupHerb SutterDavid VandevoordeMichael Wong. Apologies to the 200+ current and past members that I couldn't list. Also, please note the author lists on the various papers: a standard is written by (many) individuals, not by an anonymous committee.

You can get a better impression of the breath and depth of expertise involved by examining the author lists on the WG21 papers, but please remember there are major contributors to the standards effort who do not write a lot.

 


Will there be a C++1y?

Almost certainly -- and not just because the committee has slipped the deadline for C++0x. The plans for minor revisions, C++14, are well advanced (the features have been voted into the working draft and implemented), and the plan is for a major revision in 2017, C++17.

 


What happened to "concepts"?

"Concepts" was a feature designed to allow precise specification of requirements on template arguments. Unfortunately, the committee decided that further work on concepts could seriously delay the standard and voted to remove the feature from the working paper, see my note The C++0x "Remove Concepts" Decision and A DevX interview on concepts and the implications for C++0x for an explanation.

A radically simplified version ``concepts lite'' will be part of C++14 (as a technical report).

I have not deleted the concept sections from this document, but left them at the end:

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: "c++ templates - the complete guide, 2nd edition"是一本关于C++模板编程的全面指南。模板是C++中一种特殊的编程工具,它允许开发人员编写通用的代码,以便可以在不同的数据类型上进行重用。 这本书由两位C++专家Nicolai M. Josuttis和David Vandevoorde合著,他们详细介绍了模板编程的各个方面。第二版更新了许多新的特性和用法,以适应现代C++的发展。 本书涵盖了模板基础知识,包括模板定义、实例化和特化的原理和规则。它还详细解释了各种模板技术,如函数模板、类模板、模板别名和可变参数模板。此外,书中还介绍了如何使用模板进行元编程和泛型编程,以及模板在库设计和实现中的应用。 这本书不仅提供了理论知识,还包含了大量的示例代码和实践经验。读者可以通过这些实例深入了解模板的使用方法和技巧。书中还讨论了一些常见的问题和陷阱,并提供了解决方案和最佳实践。 "c++ templates - the complete guide, 2nd edition"适合那些希望充分利用C++模板功能的开发人员和学习者阅读。无论是初学者还是有经验的开发人员,都能从这本书中获得宝贵的知识和技巧,提高他们在C++编程中的能力和效率。 ### 回答2: 《C++模板 - 完全指南,第二版》是一本关于C++模板编程的详细指南。C++模板是一种通用编程工具,它能够在不同类型和数据结构上实现代码的复用和泛型性。这本书由David Vandevoorde和Nicolai M. Josuttis撰写,对C++模板进行了全面和深入的介绍。 这本书首先介绍了模板的基础知识,包括模板的定义、使用方法和模板参数的类型推导。然后,书中深入探讨了模板元编程,即使用模板来生成代码的技术。它涵盖了元编程的基本原理、各种技术和实用案例,帮助读者熟练掌握这一重要技能。 除此之外,这本书还详细介绍了模板的高级主题,如可变参数模板、模板特化、模板元编程中的递归和递归模板模式等。这些内容有助于读者深入理解C++模板的内部机制和更高级的用法,提升他们在模板编程中的能力和灵活性。 此外,这本书还包含了大量的示例代码和实用技巧,帮助读者更好地理解和应用模板编程。目标读者群包括有一定C++基础的开发人员、学术研究人员和C++标准委员会成员。 总之,《C++模板 - 完全指南,第二版》是一本权威和实用的C++模板编程指南。通过阅读这本书,读者可以系统地学习和掌握C++模板的基础知识和高级应用,提升他们在C++编程中的能力和效率。 ### 回答3: 《C++ Templates:完全指南,第二版》是一本介绍C++模板的书籍。模板是C++的一项强大特性,它允许我们编写通用的代码,可以适用于不同的数据类型或对象。这本书提供了全面的指导,帮助读者理解和使用C++模板。 首先,书中介绍了模板的基本概念和语法。读者可以学习如何定义和使用函数模板以及类模板。函数模板允许我们编写可以应用于多个数据类型的函数。类模板则可以创建通用的类,可以在不同的对象类型上操作。 其次,书中详细讲解了模板的实例化和特化。模板实例化是在编译时根据实际类型生成具体的函数或类。特化是指根据特定的类型重新定义模板,以适应特殊的需求。通过实例化和特化,读者可以了解如何根据不同的需求生成具体的代码。 此外,书中还介绍了模板的高级特性和技巧。包括类型推断、可变参数模板、模板元编程等。这些高级特性能够帮助我们更好地使用模板,编写更灵活和高效的代码。 最后,书中给出了一些实际应用的例子,如STL中的容器和算法。读者可以通过这些例子了解如何使用模板在实际项目中解决问题。 总的来说,《C++ Templates:完全指南,第二版》是一本深入系统介绍C++模板的书籍。通过阅读本书,读者可以全面了解和掌握C++模板的使用方法和技巧,提高编写通用和高效代码的能力。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值