GotW #4 Solution: Class Mechanics -- Herb Sutter

The solution to GotW #4 is now available:

GotW #4 Solution: Class Mechanics (updated for C++11/14)

by Herb Sutter

From the article:

... To see why, consider the following canonical forms for how operator+= and operator+ should normally be implemented for some type T.
T& T::operator+=( const T& other ) {
    //...
    return *this;
}

 

T operator+( T a, const T& b ) {
    a += b;
    return a;
}

Did you notice that one parameter is passed by value, and one by reference? That’s because if you’re going to copy from a parameter anyway, it’s often better to pass it by value, which will naturally enable a move operation if the caller passes a temporary object such as in expressions like (val1 * val2) + val3. We’ll see more on parameter passing in a future GotW. ...

.

New paper: N3692, C++ Editor's Report, May 2013 -- Stefanus Du Toit

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3692

Date: 2013-05-16

C++ Editor's Report, May 2013

by Stefanus Du Toit

This is the editor's report on applying the changes approved at Bristol to produce the updated working draft and Committee Draft that was posted here yesterday.

Excerpt:

Statistics: The latest draft adds wording from 64 CWG issues, 11 CWG papers, 36 LWG issues, 14 LWG papers, 5 SG1 issues, and 1 SG1 paper.

... For a full list of editorial changes, please see the C++ draft repository on GitHub.

GotW #3 Solution: Using the Standard Library (or, Temporaries Revisited) -- Herb Sutter

The solution to GotW #3 is now available:

GotW #3 Solution: Using the Standard Library (or, Temporaries Revisited) (updated for C++11/14)

by Herb Sutter

From the article:

With no other changes, simply using the standard find algorithm could do everything the range-based for loop did to avoid needless temporaries (and questions about them) [...] and it further increases our level of abstraction.

C++14 Committee Draft (CD) Published at isocpp.org -- Michael Wong

[Ed.: Thanks to Michael Wong for sharing his commentary and perspective on the C++14 CD while on the scene at the C++Now conference. Posted at the IBM C/C++ Cafe blog.]

C++14 Committee Draft (CD) published at isocpp.org

C++14 Committee Draft is here and can be accessed at isocpp.org. This is in keeping with the practice of greater transparency ... [and] was also announced to the C++NOW crowd by Jens Weller at the Community evening session last night.

 

New paper: N3690, Programming Languages -- C++, Committee Draft

Note: This updated working draft contains all of the updates approved at the Bristol ISO C++ meeting to make this the C++14 Committee Draft. Today our project editor Stefanus Du Toit, wth the kind help of Jonathan Wakely and our editorial committee of Daniel Kruegler, Alisdair Meredith, Mike Miller, and Richard Smith, finished applying and verifying the updates voted in at Bristol. This document has now been transmitted to SC22 for circulation for C++14's primary international comment ballot.

A new WG21 paper is available. A copy is linked below, and the paper will also appear in the next normal WG21 mailing. If you are not a committee member, please use the comments section below or the std-proposals forum for public discussion.

Document number: N3690

Date: 2013-05-15

Programming Languages -- C++, Committee Draft

Thanks once again to the over 100 people who attended the Bristol meeting, and several hundred more who helped work on reaching this C++14 feature-complete milestone!

Once the ballot has completed, the next step will be to consider and address all of the national body comments, and then circulate an updated Draft International Standard (DIS) for its possibly-final ballot one level higher in ISO/IEC JTC1. For more information about the standards process and stages, please see Standardization | ISO/IEC JTC1 Procedures.

C++Now presentations appearing on GitHub

The C++Now 2013 conference is still in flight, but presentation materials are being made available online as the conference progresses. You can find them here in their GitHub repository:

C++Now 2013 Presentations (GitHub)

Some of the highlights posted so far include:

Keynote: Optimizing the Emergent Structures of C++ (Chandler Carruth)

Library in a Week: C++11 & Boost Cookbook (I) (Jeff Garland)

Survey of Multi-Threaded Programming Support in C++11 and Boost (Rob Stewart)

A Zephyr Overview of C++11 (Leor Zolman)

A First Look at Proto-0x (Eric Niebler)

See the repo for much more...

The C++ Programming Language Fourth Edition is now shipping

My book The C++ Programming Language (Fourth Edition) is now shipping.

I got my copy (the very first copy!) on Friday. At 9am Monday, it became available on the publisher’s site, InformIT, and at 10am it had sold out. This is all very scary for an author. I have worked hard on this for about four years (not counting the 13 years it took getting the C++11 standard out), but of course a 1360-page book is huge, so I’ll find flaws. Anyway, that’s my problem.

For a description of the book, see http://www.stroustrup.com/4th.html. In particular, read the preface and the back-cover text to see if this book might be of interest to you. It aims to be the most comprehensive description of the C++ language, standard library, and the programming techniques C++ is designed to support. It is not meant to be the quickest introduction to C++11 or a first introduction to programming. My TC++PL4 web page also has an extended table of contents, the Tour of C++, and the exercises.

As ever, comments (preferably polite and constructive) and bug reports are most welcome.

GotW #2 Solution: Temporary Objects -- Herb Sutter

The solution to GotW #2 is now available:

GotW #2 Solution: Temporary Objects (updated for C++11/14)

by Herb Sutter

From the article:

Because C++ naturally enables move semantics for returned values like this string object, there’s usually little to be gained by trying to avoid the temporary when you return by value. ... For example, if the caller writes auto address = find_addr( mylist, “Marvin the Robot” );, there will be at most a cheap move (not a deep copy) of the returned temporary into address, and compilers are allowed to optimize away even that cheap move and construct the result into address directly.

But what if you did feel tempted to try to avoid a temporary in all return cases by returning a string& instead of string? Here’s one way you might try doing it that avoids the pitfall of returning a dangling reference to a local or temporary object: [...] To demonstrate why this is brittle, here’s an extra question:

For the above function, write the documentation for how long the returned reference is valid.

Go ahead, we’ll wait. ...

The questions for #3 are posted for discussion:

GotW #3: Using the Standard Library (or, Temporaries Revisited)