Login | Register   
RSS Feed
Download our iPhone app
Browse DevX
Sign up for e-mail newsletters from DevX


Overview: C++ Gets an Overhaul

In this overview of the changes proposed for the new standard, you'll get an idea of the kinds of improvements you can expect this time around.


en years after the ratification of the first ISO C++ standard, C++ is heading for no less than a revolution. C++0x, the new C++ standard due in 2009, brings a new spirit and new flesh into the software development world. Brace yourself for state-of-the-art design idioms, even better performance, and a plethora of new features such as multithreading, concepts, hash table, rvalue references, smarter smart pointers, and new algorithms. No doubt you'll find a lot to like in C++0x!

New Core Features
The two most important features of C++0x are concepts and concurrency support. Concepts enable programmers to specify constraints on template parameters, thus making generic programming and design immensely simpler and more reliable (see Douglas Gregor's excellent introduction to concepts). Variadic templates, template aliases (also called template typedefs), and static_assert—though not directly related to concepts—will also make the use of templates in generic libraries more intuitive, flexible, and less error prone.

The importance of a standardized concurrency API in C++ can't be overstated: As multicore processors are becoming widespread, you simply can't afford to remain stuck in the single-threaded era, or compromise on platform-dependent APIs. At last, there's a portable, standardized and efficient multithreading library for C++. To get a glimpse of the new concurrency facilities of C++0x, you're welcome to read Anthony Williams' brilliant introduction to multithreading in C++0x. You can find additional info about thread-local storage here.

Rvalue references are yet another silent revolution. While most users will probably not even know they exist (read my interview with Bjarne Stroustrup), rvalue references enable library designers to optimize containers and algorithms by implementing move semanticsand perfect forwarding easily, thus reducing unneeded copy operations.

Automatic type deduction is made possible by the new keywords auto and decltype which deduce the type of an object from its initializer and capture the type of an expression without having to spell it out, respectively. Adding auto and decltype also paves the way for a new function declaration syntax. The function's return type appears after the ->sign:

auto func(int x)->double {return pow(x);}

Lambda expressions and closures are another prominent feature of C++0x. A lambda expressionis a nameless function defined at the place where it's called. It is similar to a function object except that the programmer is rid of the burden of declaring a class with a constructor, defining an overloaded () operator and an instantiating a temporary object of that class—this tedium now becomes the compiler's job. Here's an example of a lambda expression:

//a lambda expression is used as an argument
myfunc([](int x, int y) -> int {return  x+y;} ) 

The lambda expression is indicated by the lambda introducer [] followed by a parameter list in parentheses. The optional return type comes next, following the ->sign. Finally, the lambda block itself is enclosed in braces.

Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.