Monday, April 02, 2012

Elements of Modern C++ Style - Herb Sutter

Herb Sutter is one of main C++ people in Microsoft, and in C++ standardization.
He wrote a brief document describing new features of C++11 language
(that used to be called C++0x). The language is now available in VS11 Beta,
and can be used for developing Windows 8 (and other) apps...

Elements of Modern C++ Style « Sutter’s Mill

“C++11 feels like a new language.” – Bjarne Stroustrup"

The C++11 standard offers many useful new features. This page focuses specifically and only on those features that make C++11 really feel like a new language compared to C++98

Here’s one quick example: Find the first element in v that’s >x and <y. In C+11, the simplest and cleanest code is to use a standard algorithm.
// C++98: write a naked loop (using std::find_if is impractically difficult)
vector::iterator i = v.begin(); // because we need to use i later
for( ; i != v.end(); ++i ) {
    if( *i > x && *i < y ) break;
}
 
// C++11: use std::find_if
auto i = find_if( begin(v), end(v), [=](int i) { return i > x && i < y; } );

The key (and not new) observation in the interview, is that .NET is good for developers productivity,
and C++ is good for getting efficient programs.
What is new is that modernized C++ could also make developers productive,
like C# and similar languages...
It may be time to learn (another) new language: C++11.

C++ @ MSDN

No comments: