http://my.oschina.net/u/186539/blog/58074
01 | /*- ========================================================== |
02 | * 文件名 :TestCpp11_1.cpp |
03 | * 开发人员:袁培荣 |
04 | * 当前版本:1.0.0.2595 |
05 | * 创建时间:2012-05-20 |
06 | * 修改时间:2012-05-20 |
07 | * 功能说明:测试编译器是否支持C++11新特性(1) |
08 | * 版权说明:版权所有 袁培荣 YuanPeirong |
09 | * 编译环境:Windows 7(x64) SP1 简体中文专业版 |
10 | * 编译器: Visual Studio 2010 SP1(中文旗舰版) |
11 | MinGW 20120426 GNU GCC 4.6.2 |
12 | MinGW Distro 9.0 GNU GCC 4.7.0 |
13 | Visual C++ 6.0 SP6(中文企业版) |
14 | - ==========================================================*/ |
15 |
16 | #include <iostream> |
17 | #include <vector> |
18 | using namespace std; |
19 |
20 | //=====1.测试右值引用和move语意 |
21 | bool is_r_value( int &&) { return true ; } |
22 | bool is_r_value( const int &) { return false ; } |
23 | |
24 | void test( int && i) |
25 | { |
26 | is_r_value(i); |
27 | is_r_value(std::move< int >(i)); |
28 | } |
29 | //==================================== |
30 |
31 | int main( int argc, char * argv[]) |
32 | { |
33 | |
34 | //=====2.测试以范围为基础的 for 循环 |
35 | int my_array[5] = {1, 2, 3, 4, 5}; |
36 | for ( int &x : my_array) |
37 | { |
38 | x *= 2; |
39 | } |
40 | //==================================== |
41 | |
42 | //=====3.测试型别推导 |
43 | constexpr int GetFive() { return 5;} |
44 | int some_value[GetFive() + 5]; |
45 | const std::vector< int > v(1); |
46 | auto a = v[0]; |
47 | decltype(v[0])b; |
48 | auto c = 0; |
49 | auto d = c; |
50 | decltype(c) e; |
51 | decltype((c)) f = e; |
52 | decltype(0) g; |
53 | //==================================== |
54 | return 0; |
55 | } |
56 |
57 |
58 |
59 | //=====4.测试初始化表达式 |
60 | class C |
61 | { |
62 | int a=7; //在类的定义时初始化非静态变量,只有C++11支持 |
63 | public : |
64 | C(); |
65 | }; |
66 | //==================================== |
67 |
68 |
69 | //==================================== |
70 | //=====测试结果 |
71 |
72 | // 测试标准:编译对测试代码不报错为支持,否则不支持 |
73 |
74 | //1.Visual Studio 2010 SP1(中文旗舰版) 全部不支持 |
75 |
76 | //2.MinGW 20120426 GNU GCC 4.6.2 |
77 | // 支持前两个,不支持后两个 |
78 | // (注意,编译时应该开启新特性 -std=c++0x 或者 -std=gnu++0x) |
79 | // 命令: g++ TestCpp11_1.cpp -o TestCpp11_1 -std=c++0x |
80 |
81 | //3.MinGW Distro 9.0 GNU GCC 4.7.0 |
82 | // 很高兴,全部支持 |
83 | // (注意,编译时应该开启新特性 -std=c++0x 或者 -std=gnu++0x) |
84 | // 命令: g++ TestCpp11_1.cpp -o TestCpp11_1 -std=c++0x |
85 |
86 | //4.Visual C++ 6.0 SP6(中文企业版) 全部不支持 |
87 | //==================================== |