近日托安装雪豹的“福”,格了XP装了win7,前段时间看了C++0X标准以及VS2010诱人的新特性,不禁心痒痒在线安装了VS2010,然后手写了这个列子用来测试新增的特性。
struct _SUT { int _a; char _c; };
int _tmain(int argc, _TCHAR* argv[]) { //auto关键字 auto i = 0.0f; cout << typeid(i).name() << " i = " << i <<endl; //静态编译断言 static_assert(sizeof(i) == 4, "sizeof(i) != 4");
vector<int> v; for (int i = 0; i < 10; i++) v.push_back(i);
//decltype关键字 & 空指针常量 decltype(i) b = 1; decltype(b) *p = nullptr; p = &b;
//lambda表达式 for_each(v.begin(), v.end(), [&i, p](int n) { i += n; www.90168.org (*p)++; }); cout << "i=" << i << "\t" << "b=" << b << endl; //右值引用 _SUT lVal = { 1, ‘c‘}; _SUT &&rVal = move(lVal); cout << "rVal._a = " << rVal._a << endl;
return 0; }
PS:VS2010好用看得见,可惜只支持C++0X中的若干条新增特性,这就是现实(编译器厂商因为某种理由拒绝标准)与理想(语言标准)的差距啊。int _tmain(int argc, _TCHAR* argv[]) { //auto关键字 auto i = 0.0f; cout << typeid(i).name() << " i = " << i <<endl; //静态编译断言 static_assert(sizeof(i) == 4, "sizeof(i) != 4");
vector<int> v; for (int i = 0; i < 10; i++) v.push_back(i);
//decltype关键字 & 空指针常量 decltype(i) b = 1; decltype(b) *p = nullptr; p = &b;
//lambda表达式 for_each(v.begin(), v.end(), [&i, p](int n) { i += n; www.90168.org (*p)++; }); cout << "i=" << i << "\t" << "b=" << b << endl; //右值引用 _SUT lVal = { 1, ‘c‘}; _SUT &&rVal = move(lVal); cout << "rVal._a = " << rVal._a << endl;
return 0; }