Modern C++ and Visual Studio
Herb Sutter gave a talk on the current state of Modern C++ during Microsoft’s Build conference. The promotion of C++ has undergone something of a renaissance these past few years at Microsoft, and Sutter has been part of directing this increased focus.
Upcoming C++ Releases
Sutter began his talk by providing a quick summary of where the ISO C++ standards are at the moment. This past February the technical discussion for C++14 was completed, and the standards committee is currently reviewing the proceedings with the intent to vote on approving this standard to be an official ISO standard later this year.
The C++14 release is considered a minor release, whereas the forthcoming C++17 standard (still under design and in discussions) is considered a major release. Microsoft’s most recent compiler preview (CTP) was released this past November. The next CTP (announce date yet to be given) is expected to contain the following features with a high degree of confidence according to Sutter:
- User-defined literals
- C++14 generalized lambda capture
- C++14 libs: std:: user-defined literals
- Inline namespaces
There is a medium certainty that the following features will be in the this CTP (meaning they could be delayed to a later release):
- Universal character names in literals
- noexcept (incl. conditional)
- char16_t, char32_t, attributes
- unrestricted unions
- consexpr (except ctors, literal types)
- constexpr (incl. ctors, literal types)
Parallel STL (A convergence of PPL, TBB, Amp, CUDA, Thrust) will be released next week on CodePlex. Sutter announced that the C++ conference Microsoft has sponsored the past two years (GoingNative) has been replaced by CPPCon, which is scheduled to take place September 7 -12, 2014.
Modern C++ Use Cases
The next portion of his talk moved from release discussions to talking about the use-cases for modern C++ in today’s application development. In Sutter’s opinion, C++ should be used when the following goals or objectives are required:
- Cross-platform portability and compatibility
- High performance and full control
- Full access to hardware and OS resources
- C++ language highlights: value types by defaults, determinism by default, contiguous by default
Sutter observes that Modern C++ is not C++98-- Modern C++ is cleaner and safer while remaining fast and flexible. That is not to say that older C++ is not supported, as in many cases it will compile albeit with warnings and suggestions from the compiler on how it can be improved.
One of the features that Modern C++ offers is simplified (from the programmer’s perspective) memory management when using
new-> make_unique or
new->make_shared. No need for delete, automatic lifetime management exception-safe.
Another area is how values types are handled more efficiently for move operations. C++11 added the idea of moving object-like types. Building on this approach, the ability exists to take ownership instead of making copies that have to then be deleted. The improved move semantics can improve the speed of legacy code simply by recompiling with C++14 capable compiler.
Writing faster code
Contiguous arrays are just as important and often missed, if you are visiting many objects, you seriously want to visit them in adjacent address order. If you are serious about performance you’ll use arrays, not just lists and arraylists.
Continuing along that theme, Sutter provided benchmarks indicating that the use of vector beats lists massively for insertion and deletion. Pre-allocating list is faster than just a regular list, but both remain much worse than Vector.
Sutter’s talk is very informative and he remains an engaging speaker. Refer to the Channel9 site to watch the full talk.
Unfortunately C++ is still a lot of ceremony
I think languages like Rust (and OCaml to a certain extent) will show that you can get close to C++ performance and still operate at a higher and abstraction and productivity.
Maybe C++ will remain the choice for writing operating systems and device drivers but for anything above we should be able to do better.
Craig Motlin Sep 01, 2014