//array

 #include <array>

 void Foo()
{
array<int,> a;
generate(a.begin(),a.end(),rand);
sort(a.begin(),a.end()); for (auto n:a)
{
cout<<n<<endl;
}
cout<<"sizeof(a)="<<sizeof(a)<<endl;
}

//auto

 #include <vector>
void Foo()
{
auto a = ;
cout<<a<<endl; auto b = 20.0f;
cout<<b<<endl; auto& c = a;
c++;
cout<<a<<endl; vector<int> vec; for(int i = ; i<; i++)
{
vec.push_back(i);
} for(auto i = vec.cbegin(); i!=vec.cend(); i++)
{
cout<<*i<<endl;
} auto pF = [&c](int i)->int{ return c+=i; };
cout<<pF()<<endl;
cout<<a<<endl;
}

//regex

 #include <regex>
void Foo()
{
if( regex_match("Hello World!",std::regex("Hello .....!")) )
{
cout<<"Math!"<<endl;
} if( regex_search("321Hello World!765",std::regex("Hello .....!")) )
{
cout<<"Search!"<<endl;
} }

//thread

 void Foo()
{
thread t1([]
{
for (int i = ; i < ; i++)
{
cout<<"t1:"<<i<<endl;
}
}
); thread t2([]
{
for (int i = ; i < ; i++)
{
cout<<"t2:"<<i<<endl;
}
}
); t1.join();
t2.join();
}

//future

 #include <future>
int Test(int a,int b)
{
cout<<"Test("<<a<<","<<b<<")"<<endl;
return a+b;
} void Foo()
{
future<int> f1 = async(Test,,);
cout<<"f1"<<endl;
future<int> f2 = async(Test,,);
cout<<"f2"<<endl;
future<int> f3 = async(Test,,);
cout<<"f3"<<endl; cout<<f1.get()<<endl<<f2.get()<<endl<<f3.get()<<endl;
}

//enum class

 void Foo()
{
#define MAKE_STR(s) #s
enum class Type
{
I = ,
II,
III,
IV,
V
}; if (==(int)Type::V)
{
cout<<MAKE_STR(Type::V);
}
}

//tuple

 tuple<int,string,float> Do()
{
return make_tuple(,"hi",20.0f);
}
void Foo()
{
int a = ;
string s = "";
float b = .0f;
tie(a,s,b) = Do(); cout<<a<<endl;
cout<<s.c_str()<<endl;
cout<<b<<endl;
}

//lambda

 #include <functional>
void Foo()
{
int a = ;
int b = ;
function<int(int)> pA = [&a,b](int i)->int{ return a+=b+i; };
cout<<pA()<<endl;
cout<<a<<endl; //function<int(int)> pB = [&a,b](int i)->int{ return b+=a+i; }; compile error : 'b': a by-value capture cannot be modified in a non-mutable lambda
cout<<b<<endl; auto pC = [&](int i)->int{ return pA(i); };
cout<<pC();
}

//final

 class A final
{
};
/*
class B : public A
{
};
*/
class C
{
virtual void c()final{ }
}; class D : public C
{
//virtual void c(){ }
};

//override

 class A
{
virtual void a(){}
}; class B : public A
{
virtual void a()override{}
//virtual void a(int i)override{} error
//virtual void c()override{} error
};

c++0x新特性实例(比较常用的)的更多相关文章

  1. C++ 0X 新特性实例(比较常用的) (转)

    转自:http://www.cnblogs.com/mrblue/p/3141456.html //array #include <array> void Foo1() { array&l ...

  2. 【学亮IT手记】Java 8新特性实例介绍

    java8,也称为jdk1.8,于2014.03.18日发布,它支持函数式编程,新的js引擎,新的日期API,新的Stream Api等. 我们主要讨论以下几个新特性: ①Lambda表达式. 允许把 ...

  3. C++0x新特性

    我是在一个帖子上摘抄的大神语录...感谢supermegaboy大神,给了详尽的解释 下文是一篇转载的Wikipedia的译文,从语言和库双方面概述了C++0x. 右值引用与转移语义 在标准C++语言 ...

  4. es6/es7/es8常用新特性总结(超实用)

    本文标题有误导性,因为我其实想写node8的新特性,说实话一下子从node v1.x跳跃到node 8.x+ 真有点受宠若惊的感觉.一直觉得node 数组. 对象.序列等的处理没有python方便,因 ...

  5. JDK8新特性(二) 流式编程Stream

    流式编程是1.8中的新特性,基于常用的四种函数式接口以及Lambda表达式对集合类数据进行类似流水线一般的操作 流式编程分为大概三个步骤:获取流 → 操作流 → 返回操作结果 流的获取方式 这里先了解 ...

  6. 分享ES6中比较常用又强大的新特性

    前言 es6有很多新东西,但是感觉常用的并不是很多,这里学习记录了一些我自己认为非常常用又强大的新特性. scoping 实用的块级作用域,let x = xxx 可以声明一个块级作用域的局部变量,简 ...

  7. ES6常用新特性

    https://segmentfault.com/a/1190000011976770?share_user=1030000010776722 该文章为转载文章!仅个人喜好收藏文章! 1.前言 前几天 ...

  8. java-API中的常用类,新特性之-泛型,高级For循环,可变参数

    API中的常用类 System类System类包含一些有用的类字段和方法.它不能被实例化.属性和方法都是静态的. out,标准输出,默认打印在控制台上.通过和PrintStream打印流中的方法组合构 ...

  9. 常用的HTML5、CSS3新特性能力检测写法

    伴随着今年10月底HTML5标准版的发布,未来使用H5的场景会越来越多,这是令web开发者欢欣鼓舞的事情.然而有一个现实我们不得不看清,那就是IE系列浏览器还占有一大部分市场份额,以IE8.9为主,w ...

随机推荐

  1. Spring-事物配置

    Spring框架支持事务管理的核心是事务管理器抽象,对于不同的数据访问框架(如Hibernate)通过实现策略接口PlatformTransactionManager,从而能支持各种数据访问框架的事务 ...

  2. 35.Android之带删除按钮EditText学习

    今天实现Android里自定义带删除功能的EditText,效果如下: 当输入内容时,EditText变为带有一个删除功能按钮的编辑框,如图: 实现代码很简单,直接上代码, 布局文件xml: < ...

  3. CSS设置技巧

    一.单位和值 1.1 颜色值 在网页中的颜色设置是非常重要,有字体颜色(color).背景颜色(background-color).边框颜色(border)等,设置颜色的方法也有很多种: 1.英文命令 ...

  4. while练习:输入一个班级的人数,然后依次输入学员成绩,计算班级学员的平均成绩和总成绩。

    Console.WriteLine("请输入班级的总人数:"); int count = int.Parse(Console.ReadLine()); ;//声明一个循环变量来记录 ...

  5. eclipse错误:Unable to read workbench state. Workbench UI layout will be reset.XML document structures

    Unable to read workbench state. Workbench UI layout will be reset.XML document structures must start ...

  6. TCP的那些事儿(上)

    TCP的那些事儿(上) 原文链接:http://coolshell.cn/articles/11564.html TCP是一个巨复杂的协议,因为他要解决很多问题,而这些问题又带出了很多子问题和阴暗面. ...

  7. Java-UDP Socket编程

    UDP 的 Java 支持 UDP 协议提供的服务不同于 TCP 协议的端到端服务,它是面向非连接的,属不可靠协议,UDP 套接字在使用前不需要进行连接.实际上,UDP 协议只实现了两个功能: 在 I ...

  8. CNN 美国有线电视新闻网 wapCNN WAP 指无线应用通讯协议 ---- 美国有线电视新闻网 的无线应用

    wapCNN  wap指无线应用通讯协议  CNN美国有线电视新闻网   固, wapCNN 美国有线电视新闻网的无线应用 -------------------------------------- ...

  9. [原]Android官方图片加载利器BitmapFun解析

    通过BitmapFun在项目中使用,结合代码了解一下BitmapFun加载图片的原理,以及最佳使用实践.本文说明不包括BitmapFun的缓存部分. Android开发在使用ListView和Grid ...

  10. javascript 快速排序

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...