简体   繁体   中英

Switching to C++11

We are going to start a long lasting project using C++ as the programming language.

I read that C++0x is going to come out in 2011, so they called it C++11.

When C++11 comes out, we will still be developing the project, and would like to know if it is possible to use any features of the new C++ standard now, to able to:

  • code faster than with the old C++ and
  • switch easily when the new standard arrives?

This page shows the parts of C++0x supported by gcc(main Unix compiler), MSVC(main Microsoft compiler) and a few others(including Intel). Extra info for Clang is here although I think their c++ support for current standards is still incomplete.

Just because a standard comes out does not mean that the compilers magically get updated - it took years for most compilers to provide reasonable support for the previous standard, and some features never got supported much, such as export (dropped from C++0x). Depending on first implementations of new features si not a great strategy either - I prefer to let others be experimenters, if I'm working to a deadline.

Also, I wouldn't be too fast to call it C++11 - the standards process is fraught with possibilities for delay.

Edit: I see you are using the RW libraries. In which case, probably many features of the new Standard won't be of immediate interest, as they are aimed at template writers and users of the C++ Standard library.

Visual C++ 2010 and latest gcc versions (-std=c++0x) have support for new features of C++11, but not all of them. In particular, you could start using the new initializer syntax with braces; that is IMHO the biggest syntax change in C++11. It is also the change that would add the most inconsistencies in your code, if one part uses C++98 style and the other uses C++11 style.

Scott Meyers (author of the "Effective C++" series) uploaded just last week the following:

Summary of C++0x Feature Availability in gcc and MSVC

This is, in a sense, similar to another link mentioned in a different answer on this thread. The main difference is that Meyers' link only contains stuff he's tried out himself. I expect it will keep getting updated in the months to come.

Also, and this is how I found out about this, he implied on comp.std.c++ that he is working on something related to C++0x educational material (apparently beyond his training course) but this is all too speculative right now, so let's just stick to the first link I provided above.

Don't think of it as switching to all the new features at once. Evaluate each new language feature on it's own merits, and the quality of its implementation.

For instance long long has been a fairly common compiler extension even before it was considered for C++0x, and the new auto syntax is useful and likely to be well-supported. You may want to be very cautious with some complicated combination of several new features like type inference with decltype for a function with the new -> syntax inside a class using variadic templates and the new rules for parsing >> .

it depends which compiler you are using.

As an example, GCC has the tr1 extension which contains some features that will be in C++11.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM