What differences, if any, between C++03 and C++11 can be detected at run-time?

后端 未结 8 1433
深忆病人
深忆病人 2020-12-02 04:44

It is possible to write a function, which, when compiled with a C compiler will return 0, and when compiled with a C++ compiler, will return 1 (the trivial sulution with

8条回答
  •  佛祖请我去吃肉
    2020-12-02 04:55

    Though not so concise... In current C++, class template name itself is interpreted as a type name (not a template name) in that class template's scope. On the other hand, class template name can be used as a template name in C++0x(N3290 14.6.1/1).

    template< template< class > class > char f( int );
    template< class > char (&f(...))[2];
    
    template< class > class A {
      char i[ sizeof f< A >(0) ];
    };
    
    bool isCpp0x() {
      return sizeof( A ) == 1;
    }
    

提交回复
热议问题