测试你的编译器是否支持c++0x(c++11)

c++出新标准了,c++11或者是c++0x

那么怎么测试你的编译器是否支持这些特性呢?

新建一个文件,main.cpp。然后敲入下面代码:

#include<iostream>

using namespace std;

int main( int argc, char** argv )
{
        auto fn = []( int a, int b ){ return a + b; };
        int c = fn( 2, 3 );
        cout<<"result:"<<c<<endl;
        return 0;
}

在编译选项中加入

-std=c++0x

所以命令如下:

g++ -Wall -std=c++0x -o main,out main.cpp

需要说明的是,c++0x是一系列的新特性组成,上面的例子中,我们只测试了

auto, 隐式函数

所以你想全面测试,就需要检查每个特性,下面列出所有的新引入的特性,同时给出了gcc哪些版本支持哪些特性

Language Feature Proposal Available in GCC?
Rvalue references N2118 GCC 4.3
    Rvalue references for *this N2439 No
[Note]
Initialization of class objects by rvalues N1610 Yes
Non-static data member initializers N2756 GCC 4.7
Variadic templates N2242 GCC 4.3
    Extending variadic template template parameters N2555 GCC 4.4
Initializer lists N2672 GCC 4.4
Static assertions N1720 GCC 4.3
auto-typed variables N1984 GCC 4.4
    Multi-declarator auto N1737 GCC 4.4
    Removal of auto as a storage-class specifier N2546 GCC 4.4
    New function declarator syntax N2541 GCC 4.4
New wording for C++0x lambdas N2927 GCC 4.5
Declared type of an expression N2343 GCC 4.3
Right angle brackets N1757 GCC 4.3
Default template arguments for function templates DR226 GCC 4.3
Solving the SFINAE problem for expressions DR339 GCC 4.4
Template aliases N2258 GCC 4.7
Extern templates N1987 Yes
Null pointer constant N2431 GCC 4.6
Strongly-typed enums N2347 GCC 4.4
Forward declarations for enums N2764
GCC 4.6
Generalized attributes N2761 Work in progress
Generalized constant expressions N2235 GCC 4.6
Alignment support N2341 No
Delegating constructors N1986 GCC 4.7
Inheriting constructors N2540 No
Explicit conversion operators N2437 GCC 4.5
New character types N2249 GCC 4.4
Unicode string literals N2442 GCC 4.5
Raw string literals N2442 GCC 4.5
Universal character name literals N2170 GCC 4.5
User-defined literals N2765 GCC 4.7
Standard Layout Types N2342 GCC 4.5
Defaulted and deleted functions N2346 GCC 4.4
Extended friend declarations N1791 GCC 4.7
Extending sizeof N2253 GCC 4.4
Inline namespaces N2535 GCC 4.4
Unrestricted unions N2544 GCC 4.6
Local and unnamed types as template arguments N2657 GCC 4.5
Range-based for N2930 GCC 4.6
Explicit virtual overrides N2928
N3206
N3272
GCC 4.7
Minimal support for garbage collection and reachability-based leak detection N2670 No
Allowing move constructors to throw [noexcept] N3050 GCC 4.6 (core language only)
Defining move special member functions N3053 GCC 4.6
Concepts [not part of C++11] N2773 Some development
[Branch]
Concurrency
Sequence points N2239 No
Atomic operations N2427 GCC 4.4
Strong Compare and Exchange N2748 No
Bidirectional Fences N2752 No
Memory model N2429 No
Data-dependency ordering: atomics and memory model N2664 No
Propagating exceptions N2179 GCC 4.4
Abandoning a process and at_quick_exit N2440 No
Allow atomics use in signal handlers N2547 No
Thread-local storage N2659 No
Dynamic initialization and destruction with concurrency N2660 No
C99 Features in C++11
__func__ predefined identifier N2340 GCC 4.3
C99 preprocessor N1653 GCC 4.3
long long N1811 GCC 4.3
Extended integral types N1988 No

版权所有,禁止转载. 如需转载,请先征得博主的同意,并且表明文章出处,否则按侵权处理.

    分享到:

Leave a Reply

Your email address will not be published. Required fields are marked *