I have some headers that fight with C++11 but I'd like to use features like initializer lists in my code. My research says that you can enable newer features at the command-line only, like:
g++ -std=c++11
What I'd really like is to put in my code:
#pragma CXX11_OFF
#include <old.hpp>
#pragma CXX11_ON
vector<int> v {1,2,3};
I haven't been able to find such a pragma. Does it exist?
According to cppreference, full support of c++11 came with gcc 4.8. 1; To have full support of c++14 (with some of the new features of c++17), instead, you need gcc 5.0 and above.
The g++ utility supports almost all mainstream C++ standards, including c++98 , c++03 , c++11 , c++14 , c++17 , and experimentally c++20 and c++23 . It also provides some GNU extensions to the standard to enable more useful features.
You can use command-line flag -std to explicitly specify the C++ standard. For example, -std=c++98 , or -std=gnu++98 (C++98 with GNU extensions) -std=c++11 , or -std=gnu++11 (C++11 with GNU extensions)
What Is "#pragma GCC optimize"? It turns on certain optimization flags for GCC. The syntax is #pragma GCC optimize (option, ...) From the official source on GCC pragmas, this pragma allows you to set global optimization flags (specified by option ) for functions that come after it.
#pragma GCC diagnostic warning "-std=c++11"
This line adds a cpp 11 flag to compiler.
No. Such a pragma does not exist.
You can find a list of all pragmas GCC supports in § 6.61 of the manual.
I don't know if there exists such a pragma. But turning C++11 on and off during the same compilation unit looks akward to me. Perhaps you should place the "old" part inside a dll and import it then in the "new" part. Then you can only compile the new part with c++11 enabled
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With