So while I was wrestling with technical difficulties with my blog, I missed some huge news. According to a post by Herb Sutter on isocpp.org, C++14 is complete.
The final draft not only passed its final ballot, it passed unanimously. According to Sutter, that means that the only changes needed before the final publication are
editorial tweaks, on the order of fixing a few spelling typos and accidentally dropped words. That means the draft is pretty much what the final standard is going to be, meaning you can confidently use it as a reference until the real thing is published (and if you really want to track the changes until then, you can check the draft on GitHub. The final standard proper should be published before the end of the year.
The best part, though – as Sutter mentions – is that multiple complete C++14 implementations already exist:
There are already multiple substantially or entirely conforming implementations (modulo bugs) of C++14 available already today or in the near future – at the same time time C++14 is published. That has never happened before for a C++ (or I believe C) standard. For C++98, the delta between publishing the standard and the first fully conforming implementation being available was about 5 years. For C++11, it was two years. For C++14, the two have merged and we have achieved “time on target.”
In other words, you could be using C++14 right now. At least with GCC, just change that “
-std=c++11” you’ve been using to “
-std=c++14“, and go for it. (Actually, I have also been using a version of the
ax_cxx_compile_stdcxx_11 macro from the Autoconf Archive, modified for C++14. It’s a trivial fix – just rename the macro file to
ax_cxx_compile_stdcxx_14.m4, and do a find/replace in the code to change all “
11” to “
14” (and all “
0x” to “
1y“, if you like), and use the macro
AX_CXX_COMPILE_STDCXX_14 rather than
AX_CXX_COMPILE_STDCXX_11 in your
configure.ac – but if people are interested I could actually post the edited files. Presumably the real Autoconf Archive will have a proper
ax_cxx_compile_stdcxx_14 macro posted before too long.)
If you haven’t been using the new C++14 features yet, you’re in for a treat. I am already almost unable to give up generic lambdas – it’s painful to go back to C++11 and have to do without them. Here are some of the neat features I’ve found a lot of use for:
- Generic lambdas – the best new feature, in my opinion.
- Deduced return types for regular functions – just set the return type to
autoand you’re done.
- Enhanced lambda capture – you don’t just need to capture by val or by ref anymore.
constexprrules – it’s much, much easier to write
make_unique()– sorely missed in C++11.
integer_sequence– a lifesaver when you’re doing template metaprogramming with variadic templates (specifically:
I had presumed I would have to make a notice that all code on this blog would be C++14 code, with an explanation of why I can be confident that it would be standardized as is and how well it is already supported, but happily it seems the Committee has pulled the rug out from under me on that one. So now I can just say “this will be a C++14 blog” (at least until the next standard), and I don’t have to justify anything. That’s awesome.
We have C++14 by Explicit C++ is licensed under a Creative Commons Attribution 4.0 International License.