//array

  1. #include <array>
  2.  
  3. void Foo()
  4. {
  5. array<int,> a;
  6. generate(a.begin(),a.end(),rand);
  7. sort(a.begin(),a.end());
  8.  
  9. for (auto n:a)
  10. {
  11. cout<<n<<endl;
  12. }
  13. cout<<"sizeof(a)="<<sizeof(a)<<endl;
  14. }

//auto

  1. #include <vector>
  2. void Foo()
  3. {
  4. auto a = ;
  5. cout<<a<<endl;
  6.  
  7. auto b = 20.0f;
  8. cout<<b<<endl;
  9.  
  10. auto& c = a;
  11. c++;
  12. cout<<a<<endl;
  13.  
  14. vector<int> vec;
  15.  
  16. for(int i = ; i<; i++)
  17. {
  18. vec.push_back(i);
  19. }
  20.  
  21. for(auto i = vec.cbegin(); i!=vec.cend(); i++)
  22. {
  23. cout<<*i<<endl;
  24. }
  25.  
  26. auto pF = [&c](int i)->int{ return c+=i; };
  27. cout<<pF()<<endl;
  28. cout<<a<<endl;
  29. }

//regex

  1. #include <regex>
  2. void Foo()
  3. {
  4. if( regex_match("Hello World!",std::regex("Hello .....!")) )
  5. {
  6. cout<<"Math!"<<endl;
  7. }
  8.  
  9. if( regex_search("321Hello World!765",std::regex("Hello .....!")) )
  10. {
  11. cout<<"Search!"<<endl;
  12. }
  13.  
  14. }

//thread

  1. void Foo()
  2. {
  3. thread t1([]
  4. {
  5. for (int i = ; i < ; i++)
  6. {
  7. cout<<"t1:"<<i<<endl;
  8. }
  9. }
  10. );
  11.  
  12. thread t2([]
  13. {
  14. for (int i = ; i < ; i++)
  15. {
  16. cout<<"t2:"<<i<<endl;
  17. }
  18. }
  19. );
  20.  
  21. t1.join();
  22. t2.join();
  23. }

//future

  1. #include <future>
  2. int Test(int a,int b)
  3. {
  4. cout<<"Test("<<a<<","<<b<<")"<<endl;
  5. return a+b;
  6. }
  7.  
  8. void Foo()
  9. {
  10. future<int> f1 = async(Test,,);
  11. cout<<"f1"<<endl;
  12. future<int> f2 = async(Test,,);
  13. cout<<"f2"<<endl;
  14. future<int> f3 = async(Test,,);
  15. cout<<"f3"<<endl;
  16.  
  17. cout<<f1.get()<<endl<<f2.get()<<endl<<f3.get()<<endl;
  18. }

//enum class

  1. void Foo()
  2. {
  3. #define MAKE_STR(s) #s
  4. enum class Type
  5. {
  6. I = ,
  7. II,
  8. III,
  9. IV,
  10. V
  11. };
  12.  
  13. if (==(int)Type::V)
  14. {
  15. cout<<MAKE_STR(Type::V);
  16. }
  17. }

//tuple

  1. tuple<int,string,float> Do()
  2. {
  3. return make_tuple(,"hi",20.0f);
  4. }
  5. void Foo()
  6. {
  7. int a = ;
  8. string s = "";
  9. float b = .0f;
  10. tie(a,s,b) = Do();
  11.  
  12. cout<<a<<endl;
  13. cout<<s.c_str()<<endl;
  14. cout<<b<<endl;
  15. }

//lambda

  1. #include <functional>
  2. void Foo()
  3. {
  4. int a = ;
  5. int b = ;
  6. function<int(int)> pA = [&a,b](int i)->int{ return a+=b+i; };
  7. cout<<pA()<<endl;
  8. cout<<a<<endl;
  9.  
  10. //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
  11. cout<<b<<endl;
  12.  
  13. auto pC = [&](int i)->int{ return pA(i); };
  14. cout<<pC();
  15. }

//final

  1. class A final
  2. {
  3. };
  4. /*
  5. class B : public A
  6. {
  7. };
  8. */
  9. class C
  10. {
  11. virtual void c()final{ }
  12. };
  13.  
  14. class D : public C
  15. {
  16. //virtual void c(){ }
  17. };

//override

  1. class A
  2. {
  3. virtual void a(){}
  4. };
  5.  
  6. class B : public A
  7. {
  8. virtual void a()override{}
  9. //virtual void a(int i)override{} error
  10. //virtual void c()override{} error
  11. };

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. 扩展KMP

    刘雅琼论文 http://wenku.baidu.com/view/8e9ebefb0242a8956bece4b3.html 论文讲的非常详细. 给定母串S,子串T,n=strlen(S),m=st ...

  2. hdu2072 字典树

    这题印象深刻,我刚接触acm时,以为这题是水题(因为是中文,又短),一直没做出.现再想想也是.可能也是我以前字符串掌握不好: 这题其实也可以用stl里的map写.这里我用字典树写的.其实这题算简单题了 ...

  3. Java基础-设计模式之-代理模式Proxy

    代理模式是对象的结构模式.代理模式给某一个对象提供一个代理对象,并由代理对象控制对原对象的引用. 代理模式是常用的Java 设计模式,它的特征是代理类与委托类有同样的接口,代理类主要负责为委托类预处理 ...

  4. StyleCop的常见错误

    所有规则的翻译(基于版本4.7.44.0): 文档规则 1.SA1600:ElementsMustBeDocumented元素必须添加注释 2.SA1601: PartialElementsMustB ...

  5. 【bzoj1061】 Noi2008—志愿者招募

    http://www.lydsy.com/JudgeOnline/problem.php?id=1061 (题目链接) 题意 给定n天,第i天需要ai个志愿者,有m类志愿者,每类志愿者工作时间为[l, ...

  6. XCode新建Class时自动加前缀(class prefix 修改前缀)

    已经建好的工程,怎么修改class prefix.如图,怎么修改下面的前缀LP,我想改为其他的,比如SH 解决方法: 1.点开Xcode右侧Utilities,Project Document-> ...

  7. myeclipse 部署应用

    昨天把MyEclipse10给安装上了,今天想在MyEclipse下启动Tomcat并在浏览器中看到写的Web页面,但是当在浏览器中输入地址时,出现了404错误,出现这个错误的原因是因为没有找到指定的 ...

  8. 使用Java的嵌套循环打印出平行四边形、等腰三角形、棱形、矩形的星星图案(Java工程师面试必备)

    第一遍是看了视频,听老师讲解嵌套循环的使用,然后到星星图形这一步,当时都觉得听明白了,但是自己去做,就是写不出来 第二遍看了赵老师的教程,看了好熟悉的感觉,还是自己写不出来 第三遍找网上关于图形的嵌套 ...

  9. Selenium2+python自动化13-Alert

    不是所有的弹出框都叫alert,在使用alert方法前,先要识别出它到底是不是alert.先认清楚alert长什么样子,下次碰到了,就可以用对应方法解决.alert\confirm\prompt弹出框 ...

  10. POJ2299Ultra-QuickSort(归并排序 + 树状数组求逆序对)

    树状数组求逆序对   转载http://www.cnblogs.com/shenshuyang/archive/2012/07/14/2591859.html 转载: 树状数组,具体的说是 离散化+树 ...