Tag Archives: c++11

C++ and Beyond

Grove Park Inn

Grove Park Inn

Hello fellow travelers, and welcome to the inaugural post of my blog!  I thought it would be appropriate to begin it with a review of the C++ and Beyond 2012 conference, hosted by industry luminaries Scott Meyers, Herb Sutter, and Andrei Alexandrescu.  This year’s conference was held August 5-8 in the historic Grove Park Inn in Asheville, NC.  Attendance was limited to 120, which encouraged a more intimate, communal experience.  Speakers and attendees shared meals together, and Meyers even led a few hiking excursions around the grounds of the Inn.

An Expected Template

Most, but not all, of the content focused on C++11 features.  Alexandrescu did not fail to deliver a few templated novelties, such as his Expected<T> , a C++ variation on the Maybe Monad, and an alternative to the traditional, but mutually-exclusive, error propagation techniques of function returns and exceptions.  He also introduced ScopeGuard11, a C++11 upgrade to his popular ScopeGuard template, enabling an RAII-patterned transaction technique for invoking arbitrary blocks of logic comprising action, continuation, rollback, and commit operations.

Fast Code

Alexandrescu also presented two sessions on writing fast code.  Some of the techniques were quite novel, such as strength reduction (substituting cheaper operations or lighter-weight data types).  I resonated with the emphasis on mathematical analysis in fine-tuning algorithms, such as the use of injection to substitute two comparisons for one, and the observation that because addition is associative, and thus inherently parallelizable, accumulating algorithms should leverage it whereever possible.


A fair amount of time was devoted to techniques for optimizing code for ILP (instruction-level parallelism), whether in concurrent applications or single-threaded ones.  I use the term “optimizing” loosely, as the techniques were really aimed at encouraging parallel execution among the ALUs within a single core, which occurs “beneath” the level of the program code.  I had mixed feelings about this part of the session.  I was impressed by Alexandrescu’s rigorous scientific method in approaching the problem, inspiring me to do likewise.  I also took note of his “questioning authority” – in this case the established itoa function, which turns out to have rather mediocre performance.  My concern was with the techniques used to optimize this code for faster execution on a single proc.  While effective, I felt the focus meandered a bit from C++, and especially idiomatic C++.

Blocking Matters

Sutter’s focus was primarily on concurrency features in C++11.  His thorough and insightful treatment of atomics, async, and non-blocking alternatives to thread synchronization (such as message queues) provided a practicum in writing idiomatic concurrent C++11.  He also tantalized with promises of future language (or library) support for non-blocking sync constructs, such as a “then” method for invoking continuations on a future.  Sutter even hinted that a monadic style of async programming might be in the wings, taking inspiration from C#’s “await” keyword.

A New Community

Sutter devoted some time to advocating for the ongoing renaissance in C++ – specifically, community.  His call to action included a centralized source of reference materials, style guidelines, FAQs, and increased availability to, and transparency of, the C++ standardization process.  This is an exciting development, for a language that, to outside appearances, has byzantine control structures, and which has the reputation for being unfriendly to beginners.

Universal References

Meyers never fails to impress me with his keen insight and ability to clearly articulate the thorniest and murkiest of subjects.  Probably the greatest single value of the conference for me was Meyers’ concept of a Universal Reference.  The ambiguous nature of T&&, which can “collapse down” to either an lvalue reference or an rvalue reference, can make template code (even more) challenging to understand and maintain.  In his excellent article on rvalue references, Microsoft’s Stephan T. Lavavej hints at this ambiguity:  “In templates, things that look like rvalue references aren’t necessarily so.”  Meyers resolves the confusion by coining the term Universal Reference to capture the dual nature of T&& in situations where T is deduced.  An aptly-named construct can do more to clarify a subject than an essay of explanation.

An Effective Excerpt

Meyers concluded with a few bits of advice on C++11, which will no doubt find their way into his next edition of Effective C++, for which he also solicited input from attendees.  One of his “gotchas” (capturing member data by reference, as default behavior) even got the attention of Sutter, who proposed a breaking change to correct it.


The three speakers are outstanding in both technical acumen and presentation skills, which made this conference one of the best I’ve attended.  In addition, the banter between them was entertaining and lively, particularly in panel discussions.  C++ is a thriving, evolving language thanks in large part to advocates like these.