测试编译器是否支持C++11新特性(1)
2012-09-15 16:40
489 查看
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 | *编译环境:Windows7(x64)SP1简体中文专业版 |
10 | *编译器:VisualStudio2010SP1(中文旗舰版) |
11 | MinGW20120426GNUGCC4.6.2 |
12 | MinGWDistro9.0GNUGCC4.7.0 |
13 | VisualC++6.0SP6(中文企业版) |
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
|
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 | autoa=v[0]; |
47 | decltype(v[0])b; |
48 | autoc=0; |
49 | autod=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.VisualStudio2010SP1(中文旗舰版)全部不支持 |
75 |
76 | //2.MinGW20120426GNUGCC4.6.2 |
77 | //支持前两个,不支持后两个 |
78 | //(注意,编译时应该开启新特性-std=c++0x或者-std=gnu++0x) |
79 | //命令:g++TestCpp11_1.cpp-oTestCpp11_1-std=c++0x |
80 |
81 | //3.MinGWDistro9.0GNUGCC4.7.0 |
82 | //很高兴,全部支持 |
83 | //(注意,编译时应该开启新特性-std=c++0x或者-std=gnu++0x) |
84 | //命令:g++TestCpp11_1.cpp-oTestCpp11_1-std=c++0x |
85 |
86 | //4.VisualC++6.0SP6(中文企业版)全部不支持 |
87 | //==================================== |
相关文章推荐
- 测试编译器是否支持C++11新特性(1)
- Sophus VS2010编译不支持?C++11语法的缘故。那有没有不带C++11特性的Sophus版本呢?
- cmake检测g++编译器是否支持c++11
- 【工具用法】如何使Dev C++支持C++11特性
- html5 检测浏览器是否支持新特性
- ubuntu12.04 gcc和g++支持 c++11特性
- Visual Studio, GCC, Clang, Intel 对 C++11 特性的支持一览表
- Visual Studio 2012 Express 较好支持 C++11 新特性
- C++11 Features in Visual C++ 11 - VS2010对C++11特性支持的情况
- C++11 Features in Visual C++ 11 - VS2010对C++11特性支持的情况
- HTML5特性 > 本地储存 >检测是否支持本地存储(Local Storage,sessionStorage)
- Qt Creator 增加支持c++11特性
- 关于html5支持与否的判断(JS检测是否支持HTML5新特性)
- Visual Studio 2012 Express 较好支持 C++11 新特性
- Eclipse CDT C++11/C++0x support 支持c++11特性例如shared_ptr
- Eclipse开发linux c/cpp---支持c++11特性
- [转载]Visual Studio, GCC, Clang, Intel 对 C++11 特性的支持一览表
- CentOS 编译安装gcc 4.8 为了支持C++11新特性
- 使xcode工程支持c++11特性