VS2010中的C++0x特性
来源:互联网 发布:阿里云免费cdn加速 编辑:程序博客网 时间:2024/05/29 14:17
#include <iostream>#include <vector>#include <algorithm>using namespace std;//自动类型 + 匿名函数void Case1(){vector<int> v;for (int i = 0; i < 10; ++i) {v.push_back(i);}auto fun = [](int n) -> void { cout << n << " "; };for_each(v.begin(), v.end(), fun);cout << endl;}//自动类型 + 匿名函数 + 匿名函数构造参void Case2(){vector<int> v;for (int i = 0; i < 10; ++i) {v.push_back(i);}int x = 5;int y = 6;auto fun = [x,y](int n) -> void { cout << n << "-" << x << "-" << y <<endl; };for_each(v.begin(), v.end(), fun);cout << endl;}//自动类型 + 匿名函数 + 匿名函数引用构造参void Case3(){vector<int> v;for (int i = 0; i < 10; ++i) {v.push_back(i);}int x = 5;int y = 6;auto fun = [&x, &y](int n) -> void { cout << n << "-" << x << "-" << y <<endl; x++; y++; };for_each(v.begin(), v.end(), fun);cout << endl;}//自动类型 + 匿名函数 + 匿名函数引用构造参 + 友元常量对象class Case4_Class{public:Case4_Class():m_toys(1){}void text(const vector<int>& v) const {for_each(v.begin(), v.end(), [this](int n) {cout << this->m_toys << endl;});}private:int m_toys;};void Case4(){vector<int> v;for (int i = 0; i < 10; ++i) {v.push_back(i);}Case4_Class c4;c4.text(v);}//编译器逻辑查验void Case5(){const bool ret = false;//static_assert(ret, "Case5 requires N < 2.");}//类型推算 + 完美转发class Case6_Class{public:template <typename T, typename U>auto operator()(T&& t, U&& u) ->decltype( std::forward<T>(t) + std::forward<U>(u)){return std::forward<T>(t) + std::forward<U>(u);}};void Case6(){cout<< Case6_Class()(1,2)<<endl;;}//外部模板void main(){Case6();system("pause");}
- VS2010中的C++0x特性
- VS2010 中的 C++ 0x 新特性:Lambdas、auto 和 static_assert
- VS2010 中的 C++ 0x 新特性:Lambdas、auto 和 static_assert
- VS2010中的C++0x特性 以后有时间在看
- VS2010 Beta2中,4个重要的新特性。号称C++0x的“四大天王”
- C 1X 新增特性
- objective-c中的特性
- objective-c中的特性
- Net4.0---VS2010新特性
- VC10中的C++0x特性:Lambdas,auto,以及 static_assert
- Visual Assist X 在VS2010中的破解
- cocos2d-x在vs2010中的配置
- Objective-c中的C特性
- Object-C中的特性-----property
- Objective-C中的属性特性
- C++0x新特性
- C++0x新特性
- C++0x新特性
- C++成员函数的重载,继承,覆盖和隐藏
- AndroidHttpClient类的分析,与DefaultHttpClient的区别
- Android HAL 开发 (2)
- android--获取手机的IMSI码,并判断是中国移动\中国联通\中国电信
- 标准C++中的string类的用法总结
- VS2010中的C++0x特性
- Android HAL 开发 (3)
- Sublime Text2 使用及插件配置
- 使用 Python 实现多进程
- Android HAL 开发 (4)
- MSSQL like 查询区分大小写的问题
- Android HAL 开发 (5)
- Checkbox多选按钮的使用
- struts2乱码解决方案