c++11介绍
- 中文名
- C++11
- 外文名
- C++11
- 标准版本
- C++标准第三版
- 发布时间
- 2011年8月12日
- 出版时间
- 2011年9月
- 标准文件号
- ISO/IEC 14882:2011
目录
简介
C++语言的标准化进程版本变更
现状
编译器实现情况示例
类型推导与auto关键字
|
1
|
auto otherVariable = 5;//otherVariable被按照int型来编译 |
|
1
|
auto someStrangeCallableType = boost::bind(&SomeFunction,_2,_1,someObject); |
|
1
2
|
int someInt;decltype(someInt) otherIntegerVariable = 5; |
|
1
|
for(vector<int>::const_iteratoritr=myvec.begin(); itr!=myvec.end(); ++itr) |
|
1
|
for(auto itr = myvec.begin(); itr != myvec.end(); ++itr) |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
#include<vector>int main(){ const std::vector<int>v(1); auto a = v[0];//a为int类型 decltype(v[0]) b = 0;//b为const int&类型,即std::vector<int>::operator[](size_type)const的返回类型 auto c = 0;//c为int类型 auto d = c;//d为int类型 decltype(c) e;//e为int类型,c实体的类型 decltype((c)) f = e;//f为int&类型,因为(c)是左值 decltype(0) g;//g为int类型,因为0是右值 return 0;} |
外部模板
|
1
2
3
4
5
|
int my_array[5]={1, 2, 3, 4, 5};for(int& x : my_array){x *= 2;} |
| 功能 |
VS2011 |
VS2013 | g++ 4.7 |
Clang 3.1 |
| auto关键字 |
Yes |
Yes |
Yes | Yes |
| decltype关键字 | Yes |
Yes |
Yes | Yes |
| 右值引用(Rvalue references)与移动语义(move semantics) | Yes |
Yes |
Yes | Yes |
| Lambda表达式 |
Yes |
Yes |
Yes | Yes |
| nullptr关键字 | Yes |
Yes |
Yes | Yes |
| 静态断言(static_assert)关键字[4] |
Yes |
Yes |
Yes | Yes |
| 基于范围的循环(Range based for loop)语法[5] | Yes |
Yes |
Yes | Yes |
| 函数返回类型后置(Trailing return type in functions)语法 | Yes |
Yes |
Yes | Yes |
| final关键字 | Yes |
Yes |
Yes | Yes |
| override关键字 | Yes |
Yes |
Yes | Yes |
| 强类型枚举(Strongly typed enums) | Yes |
Yes |
Yes | Yes |
| 前置枚举声明(Forward declared enums) |
Yes |
Yes |
Yes | Yes |
| 外部模板(extern templates) | Yes |
Yes |
Yes | Yes |
| 模板右尖括号嵌套(>> for nested templates) | Yes |
Yes |
Yes | Yes |
| Local and unnamed types as template arguments | Yes |
Yes |
Yes | Yes |
| 变参宏(Variadic macros) | Yes |
Yes |
Yes | Yes |
| 新内建类型(New built-in types) | Partial(部分) | ? | Yes | Yes |
| Initializer_lists容器 | No | ? | Yes | Yes |
| 显式类型转换运算符(explicit type conversion operators) | No | Yes |
Yes | Yes |
| 内联命名空间(Inline namespaces) | No | ? | Yes | Yes |
|
sizeof用在没实例时的非静态成员
(sizeof on non-static data members without an instance)
|
No | ? | Yes | Yes |
| 改变union成员限制(Changed restrictions on union members) | No | ? | Yes | Yes |
| Raw string literals |
No | Yes | Yes | Yes |
| User defined literals |
No | ? | Yes | Yes |
| Encoding support in literals |
No | ? | Yes | Yes |
| Arbitrary expressions in template deduction contexts |
No | ? | Yes | Yes |
| 默认方法(Defaulted methods) |
No | Yes(有条件支持)[6] | Yes | Yes |
| 删除方法(Deleted methods) |
No | Yes(有条件支持)[6] | Yes | Yes |
| 非静态成员初始化(Non-static data member initializers) |
No | ? | Yes | Yes |
| 变参模板(Variadic templates) | No | ? | Yes | Yes |
|
函数模板中的默认模板参数
(Default template arguments in function templates)
|
No | ? | Yes | Yes |
| 模板别名(Template aliases) | No | ? | Yes | Yes |
| 前置构造函数(Forwarding constructors) | No | ? | Yes | Yes |
| noexcept关键字 | No | ? | Yes | Yes |
| constexpr关键字 |
No | ? | Yes | Yes |
| Alignment 支持 |
Partial(部分) | Partial(部分) | Yes | Yes |
| *this的右值引用 | No | ? | No | Yes |
| C99兼容性(C99compatibility) | Partial(部分) | Partial(部分) | Partial(部分) | Partial(部分) |
| 线程本地存储(Thread local storage) | Partial(部分) | Partial(部分) | Partial(部分) | |
| 构造函数继承(Inheriting constructors) | No | ? | No | No |
| Generalized attributes |
No | ? | No | No |
VS C++11功能支持表(总表)
|
C++11 Core Language Features
|
Visual Studio 2010
|
Visual Studio 2012
|
Visual Studio 2013
|
|---|---|---|---|
|
Rvalue referencesv0.1,v1.0,v2.0,v2.1,v3.0
|
v2.0
|
v2.1*
|
v2.1*
|
|
ref-qualifiers
|
No
|
No
|
No
|
|
Non-static data member initializers
|
No
|
No
|
Yes
|
|
Variadic templatesv0.9,v1.0
|
No
|
No
|
Yes
|
|
Initializer lists
|
No
|
No
|
Yes
|
|
static_assert
|
Yes
|
Yes
|
Yes
|
|
autov0.9,v1.0
|
v1.0
|
v1.0
|
v1.0
|
|
Trailing return types
|
Yes
|
Yes
|
Yes
|
|
Lambdasv0.9,v1.0,v1.1
|
v1.0
|
v1.1
|
v1.1
|
|
decltypev1.0,v1.1
|
v1.0
|
v1.1**
|
v1.1
|
|
Right angle brackets
|
Yes
|
Yes
|
Yes
|
|
Default template arguments for function templates
|
No
|
No
|
Yes
|
|
Expression SFINAE
|
No
|
No
|
No
|
|
Alias templates
|
No
|
No
|
Yes
|
|
Extern templates
|
Yes
|
Yes
|
Yes
|
|
Yes
|
Yes
|
Yes
|
|
|
Strongly typed enums
|
Partial
|
Yes
|
Yes
|
|
Forward declared enums
|
No
|
Yes
|
Yes
|
|
No
|
No
|
No
|
|
|
constexpr
|
No
|
No
|
No
|
|
TR1
|
Partial
|
Partial
|
|
|
Delegating constructors
|
No
|
No
|
Yes
|
|
Inheriting constructors
|
No
|
No
|
No
|
|
Explicit conversion operators
|
No
|
No
|
Yes
|
|
char16_t/char32_t
|
No
|
No
|
No
|
|
Unicode string literals
|
No
|
No
|
No
|
|
Raw string literals
|
No
|
No
|
Yes
|
|
Universal character names in literals
|
No
|
No
|
No
|
|
User-defined literals
|
No
|
No
|
No
|
|
Standard-layout and trivial types
|
No
|
Yes
|
Yes
|
|
Defaulted and deleted functions
|
No
|
No
|
Yes*
|
|
Extended friend declarations
|
Yes
|
Yes
|
Yes
|
|
Extended sizeof
|
No
|
No
|
No
|
|
Inline namespaces
|
No
|
No
|
No
|
|
Unrestricted unions
|
No
|
No
|
No
|
|
Local and unnamed types as template arguments
|
Yes
|
Yes
|
Yes
|
|
Range-based for-loop
|
No
|
Yes
|
Yes
|
|
override and finalv0.8,v0.9,v1.0
|
Partial
|
Yes
|
Yes
|
|
Minimal GC support
|
Yes
|
Yes
|
Yes
|
|
noexcept
|
No
|
No
|
No
|
并发能力
|
C++11 Core Language Features: Concurrency
|
Visual Studio 2010
|
Visual Studio 2012
|
Visual Studio 2013
|
|---|---|---|---|
|
Reworded sequence points
|
N/A
|
N/A
|
N/A
|
|
Atomics
|
No
|
Yes
|
Yes
|
|
Strong compare and exchange
|
No
|
Yes
|
Yes
|
|
Bidirectional fences
|
No
|
Yes
|
Yes
|
|
Memory model
|
N/A
|
N/A
|
N/A
|
|
Data-dependency ordering
|
No
|
Yes
|
Yes
|
|
Data-dependency ordering: function annotation
|
No
|
No
|
No
|
|
exception_ptr
|
Yes
|
Yes
|
Yes
|
|
quick_exit
|
No
|
No
|
No
|
|
Atomics in signal handlers
|
No
|
No
|
No
|
|
Thread-local storage
|
Partial
|
Partial
|
Partial
|
|
Magic statics
|
No
|
No
|
No
|
VS C++ 11语言功能支持表:C99
|
C++11 Core Language Features: C99
|
Visual Studio 2010
|
Visual Studio 2012
|
Visual Studio 2013
|
|---|---|---|---|
|
__func__
|
Partial
|
Partial
|
Partial
|
|
C99 preprocessor
|
Partial
|
Partial
|
Partial
|
|
long long
|
Yes
|
Yes
|
Yes
|
|
Extended integer types
|
N/A
|
N/A
|
N/A
|
c++11介绍的更多相关文章
- C++11 并发指南一(C++11 多线程初探)
引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...
- 第三部分:Android 应用程序接口指南---第一节:应用程序组件---第一章1-1.Fragment
第1-1章 Fragments 在Activity中的fragment代表的是一种行为或用户界面的一部分.你可以在activity中结合多个fragments创建一个多面板UI,并可以在多个activ ...
- C++11 并发指南一(C++11 多线程初探)(转)
引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...
- C++11/14笔记
目录 语言层面 模板表达式中的空格 nullptr和std::nullptr_t 自动推导类型----auto 一致性初始化----Uniform Initialization 初始化列表(initi ...
- 【C/C++开发】C++11 并发指南一(C++11 多线程初探)
引言 C++11 自2011年发布以来已经快两年了,之前一直没怎么关注,直到最近几个月才看了一些 C++11 的新特性,今后几篇博客我都会写一些关于 C++11 的特性,算是记录一下自己学到的东西吧, ...
- 高级php面试题(转)
一.mysql相关知识 1. mysql优化方式 MYSQL 优化常用方法 mysql 性能优化方案 2.如何分库分表 ...
- 高级php面试题
在网上看到一些高级php 的面试题目.. 最近接连面试了几家公司,有些重要问题记录一下,督促自己学习提高,同时希望给朋友们一些帮助.内容很多,一点点完善,一步步学习..有些是面试被问,有些是招聘要求, ...
- 了不起的Node.js: 将JavaScript进行到底(Web开发首选,实时,跨多服务器,高并发)
了不起的Node.js: 将JavaScript进行到底(Web开发首选,实时,跨多服务器,高并发) Guillermo Rauch 编 赵静 译 ISBN 978-7-121-21769-2 2 ...
- Android 使用 DownloadManager 管理系统下载任务的方法,android管理系统
从Android 2.3(API level 9)开始Android用系统服务(Service)的方式提供了Download Manager来优化处理长时间的下载操作.Download Manager ...
随机推荐
- TEA加密算法的C/C++实现
TEA(Tiny Encryption Algorithm) 是一种简单高效的加密算法,以加密解密速度快,实现简单著称.算法真的很简单,TEA算法每一次可以操作64-bit(8-byte),采用128 ...
- 简单的QT绘图程序(把全部的点都记录下来,然后在paintEvent里使用drawLine函数进行绘制,貌似效率很低。。。)
当初在学MFC时,最经典的入门实例就是绘图程序,其作用相当于Console Application 下的Hello World了吧. 如今入手QT,不免怀旧,于是也写了一个绘图程序,虽然简单,却也是入 ...
- C# 编写服务 Windows service
1.编写服务教程 http://jingyan.baidu.com/article/ea24bc395e16f8da62b331e7.html 这里不多说了. 给大家一个连接,上面有详细的教程,下面说 ...
- Spring Task Scheduler - No qualifying bean of type [org.springframework.scheduling.TaskScheduler] is defined
1. Overview In this article, we are discussing the Springorg.springframework.beans.factory.NoSuchBea ...
- The type R is already defined 错误解决办法
今天在导入一个开源项目的时候遇到了The type R is already defined的错误,试过了删除R,clear project都还是报这个错,Google一下之后找到了解决办法在 Pro ...
- SqlServer 数据库日志无法收缩处理过程
今天按常用方法收缩一个测试用的数据库日志,发现没法收缩! dbcc sqlperf(logspace) USE [dbname] GO ALTER DATABASE [dbname] SET ...
- Android 消息处理源代码分析(1)
Android 消息处理源代码分析(1) 在Android中,通常被使用的消息队列的代码在文件夹\sources\android-22\android\os下,涉及到下面几个类文件 Handler.j ...
- ViewPager的Adapter中视图重用
ViewPager的PagerAdapter不像ListView/GridView的BaseAdapter,它是没有内部视图重用机制的,也就是说我先inflate出来一个,然后调用destroyIte ...
- 设计模式入门之职责链模式Chain Of Responsibility
//职责链模式:使多个对象都有机会处理请求,从而避免请求的发送者和接受者之间的耦合关系.将这些对象连成一条链,并沿着这条链传递该请求,直到有一个对象处理它为止. //实例:申请费用的功能,不同金额的费 ...
- python中的tab补全功能添加
用Python时没有tab补全还是挺痛苦的,记录一下添加该功能的方法利人利己 1. 先准备一个tab.py的脚本 shell> cat tab.py #!/usr/bin/python # py ...