This week I’ve been at BoostCon, a C++ conference focused on the Boost libraries, TR1, TR2 and C++0X. The weather here in Aspen, Colorado has been fantastic. I was expecting cool temperatures (Aspen is at 8,000 feet elevation), but it’s been sunny and in the 70s every day. The conference organizers wisely gave us 2+ hour lunch breaks every day, so I’ve had the chance to explore downtown, go hiking, and mostly keep up with work email, too. Aspen’s a pretty hip place — an unlikely combination of old mining town mixed with modern ski resort plus a dash of Beverly Hills thrown in for good measure. It surely has more excellent shops and restaurants per capita than anywhere else on earth.
A few things have struck me about the conference. First, there are a lot of really talented C++ developers who are expanded and extending the language in amazing directions. Second, one of the unstated themes of the conference is C++ metaprogramming. Scott Meyers talked about how many meta languages there are in C++. Here are a few: printf formatting (one of the most cryptic, surely), template metaprogramming, iostream input and output, lambda functions, and coming soon in C++0X, concepts. Third, game developers have some exciting things to look forward to in C++0X.
C++0X is the code name for the next version of the C++ Standard. The hope of the C++ Standards Committee (many of whom are at the conference) is that the next version will be in place by the end of the decade — hence the 0X, hopefully meaning ’09. The running joke is that 0X may turn out to mean 0A or 0B, but we’ll see. At least two things in C++0X are extremely compelling for game programmers: rvalue references and concepts.
Rvalue references are a new type of reference. The advantage of rvalue references is that in many cases they allow objects to be moved rather than copied. As Andrei Alexandrescu has said, "creating, copying around, and destroying temporary objects is the favorite indoor sport of your C++ compiler." This copying behavior causes huge bottlenecks in games. We tend to work around that behavior in all sorts of unnatural ways: copy-on-write objects, smart pointers, and so forth. With rvalue references, the problem Just Goes Away. With C++0X, the STL will be updated to support rvalue references and move constructors. Howard Hinnant, the designer of rvalue references, showed example code using the STL that ran 7X faster with C++0X. Yes, 7X faster. That’s the kind of optimization I like to see.
Concepts are a new, well, concept in C++. They allow you to state requirements for template code that are validated at compile time rather than at template instantiation. Today, using any type of template code is an exercise in frustration for most programmers. Errors give little indication of whether the problem lies in the template itself or in the programmer’s use of the template. Concepts change the whole equation, allowing template code to be fully validated by the compiler. I predict that concepts will finally allow the average programmer to use template libraries with ease, gaining all the performance advantages of templates without all the pain.
I can’t wait for C++0X.