c++0x新特性实例(比较常用的)
//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新特性实例(比较常用的)的更多相关文章
- C++ 0X 新特性实例(比较常用的) (转)
转自:http://www.cnblogs.com/mrblue/p/3141456.html //array #include <array> void Foo1() { array&l ...
- 【学亮IT手记】Java 8新特性实例介绍
java8,也称为jdk1.8,于2014.03.18日发布,它支持函数式编程,新的js引擎,新的日期API,新的Stream Api等. 我们主要讨论以下几个新特性: ①Lambda表达式. 允许把 ...
- C++0x新特性
我是在一个帖子上摘抄的大神语录...感谢supermegaboy大神,给了详尽的解释 下文是一篇转载的Wikipedia的译文,从语言和库双方面概述了C++0x. 右值引用与转移语义 在标准C++语言 ...
- es6/es7/es8常用新特性总结(超实用)
本文标题有误导性,因为我其实想写node8的新特性,说实话一下子从node v1.x跳跃到node 8.x+ 真有点受宠若惊的感觉.一直觉得node 数组. 对象.序列等的处理没有python方便,因 ...
- JDK8新特性(二) 流式编程Stream
流式编程是1.8中的新特性,基于常用的四种函数式接口以及Lambda表达式对集合类数据进行类似流水线一般的操作 流式编程分为大概三个步骤:获取流 → 操作流 → 返回操作结果 流的获取方式 这里先了解 ...
- 分享ES6中比较常用又强大的新特性
前言 es6有很多新东西,但是感觉常用的并不是很多,这里学习记录了一些我自己认为非常常用又强大的新特性. scoping 实用的块级作用域,let x = xxx 可以声明一个块级作用域的局部变量,简 ...
- ES6常用新特性
https://segmentfault.com/a/1190000011976770?share_user=1030000010776722 该文章为转载文章!仅个人喜好收藏文章! 1.前言 前几天 ...
- java-API中的常用类,新特性之-泛型,高级For循环,可变参数
API中的常用类 System类System类包含一些有用的类字段和方法.它不能被实例化.属性和方法都是静态的. out,标准输出,默认打印在控制台上.通过和PrintStream打印流中的方法组合构 ...
- 常用的HTML5、CSS3新特性能力检测写法
伴随着今年10月底HTML5标准版的发布,未来使用H5的场景会越来越多,这是令web开发者欢欣鼓舞的事情.然而有一个现实我们不得不看清,那就是IE系列浏览器还占有一大部分市场份额,以IE8.9为主,w ...
随机推荐
- 扩展KMP
刘雅琼论文 http://wenku.baidu.com/view/8e9ebefb0242a8956bece4b3.html 论文讲的非常详细. 给定母串S,子串T,n=strlen(S),m=st ...
- hdu2072 字典树
这题印象深刻,我刚接触acm时,以为这题是水题(因为是中文,又短),一直没做出.现再想想也是.可能也是我以前字符串掌握不好: 这题其实也可以用stl里的map写.这里我用字典树写的.其实这题算简单题了 ...
- Java基础-设计模式之-代理模式Proxy
代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理 ...
- StyleCop的常见错误
所有规则的翻译(基于版本4.7.44.0): 文档规则 1.SA1600:ElementsMustBeDocumented元素必须添加注释 2.SA1601: PartialElementsMustB ...
- 【bzoj1061】 Noi2008—志愿者招募
http://www.lydsy.com/JudgeOnline/problem.php?id=1061 (题目链接) 题意 给定n天,第i天需要ai个志愿者,有m类志愿者,每类志愿者工作时间为[l, ...
- XCode新建Class时自动加前缀(class prefix 修改前缀)
已经建好的工程,怎么修改class prefix.如图,怎么修改下面的前缀LP,我想改为其他的,比如SH 解决方法: 1.点开Xcode右侧Utilities,Project Document-> ...
- myeclipse 部署应用
昨天把MyEclipse10给安装上了,今天想在MyEclipse下启动Tomcat并在浏览器中看到写的Web页面,但是当在浏览器中输入地址时,出现了404错误,出现这个错误的原因是因为没有找到指定的 ...
- 使用Java的嵌套循环打印出平行四边形、等腰三角形、棱形、矩形的星星图案(Java工程师面试必备)
第一遍是看了视频,听老师讲解嵌套循环的使用,然后到星星图形这一步,当时都觉得听明白了,但是自己去做,就是写不出来 第二遍看了赵老师的教程,看了好熟悉的感觉,还是自己写不出来 第三遍找网上关于图形的嵌套 ...
- Selenium2+python自动化13-Alert
不是所有的弹出框都叫alert,在使用alert方法前,先要识别出它到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决.alert\confirm\prompt弹出框 ...
- POJ2299Ultra-QuickSort(归并排序 + 树状数组求逆序对)
树状数组求逆序对 转载http://www.cnblogs.com/shenshuyang/archive/2012/07/14/2591859.html 转载: 树状数组,具体的说是 离散化+树 ...