May 2013

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)

 

 

Some Subtleties of Aliasing -- Andrew Koenig

Why "aliasing can cause paradoxical behavior"...

Some Subtleties of Aliasing

by Andrew Koenig

 

... As an example of a problem with this code, I suggested that it might be called by writing

 

scale(v, v[n]);

with the aim of dividing every element of v by v[n], but that this call would actually do something else entirely. From the comments on the article, I think that some readers were unclear about what that something else might be. To understand this call's behavior in detail, we have to look at the code more closely. ...

Quick Q: What's the best way to return multiple values? -- StackOverflow

Another example of how adding a feature, in this case move semantics, makes using the language simpler:

Interface for returning a bunch of values

I have a function that takes a number and returns up to that many things (say, ints). What's the cleanest interface?

  1. Return a vector<int>. The vector would be copied several times, which is inefficient.
  2. Return a vector<int>*. My getter now has to allocate the vector itself, as well as the elements. There are all the usual problems of who has to free the vector, the fact that you can't allocate once and use the same storage for many different calls to the getter, etc. This is why STL algorithms typically avoid allocating memory, instead wanting it passed in.
  3. Return a unique_ptr<vector<int>>. It's now clear who deletes it, but we still have the other problems.
  4. Take a vector<int> as a reference parameter. The getter can push_back() and the caller can decide whether to reserve() the space. However, what should the getter do if the passed-in vector is non-empty? Append? Overwrite by clearing it first? Assert that it's empty? It would be nice if the signature of the function allowed only a single interpretation.
  5. Pass a begin and end iterator. Now we need to return the number of items actually written (which might be smaller than desired), and the caller needs to be careful not to access items that were never written to.
  6. Have the getter take an iterator, and the caller can pass an insert_iterator.
  7. Give up and just pass a char *. smile

Post-Bristol standards papers mailing available

The official post-meeting standards papers mailing is now available. It includes papers adopted at the meeting, updated papers, and updated issues lists.

Please direct discussion to the public std-proposals forum.

 

WG21 Number Title Author Document Date Mailing Date Previous Version Subgroup Disposition
SD-1 2013 PL22.16/WG21 document list Clark Nelson 2013-05-07 2013-05      
SD-2 ISO WG21 and INCITS PL22.16 membership list Clark Nelson 2013-05-06 2013-05      
N3621 Minutes, WG21 Teleconference 2013-03-29 Kyle Kloepper 2013-03-29 2013-05      
N3622 Minutes: WG21 Meeting No. 55, 15-20 April 2013 - Bristol, UK Kyle Kloepper 2013-05-03 2013-05      
N3623 Minutes: PL22.16 Meeting No. 60, 15-20 April 2013 - Bristol, UK Kyle Kloepper 2013-05-03 2013-05      
N3624 Core Issue 1512: Pointer comparison vs qualification conversions (revision 3) Jens Maurer 2013-04-15 2013-05 N3498 Core Adopted 2013-04
N3625 A URI Library for C++ G. Matthews, D. Berris 2013-04-30 2013-05 N3507 Networking  
N3626 Floating-Point Typedefs Having Specified Widths P. Bristow, C. Kormanyos, J. Maddock 2013-04-05 2013-05   Numerics  
N3627 Relaxed switch statement Zhihao Yuan 2013-02-07 2013-05   Evolution  
N3628 C and C++ Compatibility Bjarne Stroustrup 2013-04-08 2013-05      
N3629 Simplifying C++0x Concepts Doug Gregor 2013-04-09 2013-05   Concepts  
N3630 async, ~future, and ~thread (Revision 1) Herb Sutter 2013-04-12 2013-05 N3451 Concurrency Revised N3636, N3637
N3631 C11: The New C Standard Thomas Plum   2013-05      
N3632 Additional std::async Launch Policies Peter Dimov 2013-04-11 2013-05   Concurrency  
N3633 What can signal handlers do? (CWG 1441) Hans Boehm 2013-4-25 2013-05 N3618 Concurrency  
N3634 Improvements to std::future<T> and Related APIs N. Gustafsson, A. Laksberg, H. Sutter, S. Mithani 2013-05-02 2013-05 N3558 Concurrency  
N3635 Towards restrict-like semantics for C++ M. Wong, R. Silvera, R. Mak, C. Cambly, et al. 2013-04-29 2013-05   Evolution  
N3636 ~thread should join Herb Sutter 2013-04-17 2013-05 N3630 Concurrency  
N3637 async and ~future (Revision 3) Herb Sutter 2013-04-17 2013-05 N3630 Concurrency  
N3638 Return type deduction for normal functions Jason Merrill 2013-04-17 2013-05 N3582 Core Adopted 2013-04
N3639 Runtime-sized arrays with automatic storage duration (revision 5) Jens Maurer 2013-04-16 2013-05 N3497 Core Adopted 2013-04
N3640 Extending shared_ptr to Support Arrays Peter Dimov 2013-04-15 2013-05   Library  
N3641 Extending make_shared to Support Arrays Peter Dimov 2013-05-02 2013-05   Library  
N3642 User-defined Literals for Standard Library Types (part 1 - version 4) Peter Sommerlad 2013-04-18 2013-05 N3531 Library Adopted 2013-04
N3643 Range Adaptor for Selecting from Pair or Tuple Alan Talbot 2013-04-16 2013-05 N3585 Ranges  
N3644 Null Forward Iterators Alan Talbot 2013-04-18 2013-05 N3585 Library Adopted 2013-04
N3645 Splicing Maps and Sets (Revision 1) A. Talbot, H. Hinnant, J. Dennett, J. Wakely 2013-05-04 2013-05 N3586 Library  
N3646 Network byte order conversion Robert Pratte 2013-04-16 2013-05 N3620 Networking  
N3647 Minutes: PL22.16 Meeting No. 59, 15-19 October 2012 Portland, Oregon, USA Kyle Kloepper 2013-04-15 2013-05 N3455    
N3648 Wording Changes for Generalized Lambda-capture D. Vandevoorde, V. Voutilainen 2013-04-17 2013-05 N3610 Evolution Adopted 2013-04
N3649 Generic (Polymorphic) Lambda Expressions (Revision 3) F. Vali, H. Sutter, D. Abrahams 2013-04-19 2013-05 N3559 Evolution Adopted 2013-04
N3650 Resumable Functions N. Gustafsson, D. Brewis, H. Sutter, S. Mithani 2013-05-02 2013-05 N3564 Concurrency  
N3651 Variable Templates (Revision 1) Gabriel Dos Reis 2013-04-19 2013-05 N3615 Evolution Adopted 2013-04
N3652 Relaxing constraints on constexpr functions / constexpr member functions and implicit const Richard Smith 2013-04-18 2013-05 N3597, N3598 Evolution Adopted 2013-04
N3653 Member initializers and aggregates V. Voutilainen, R. Smith 2013-04-17 2013-05 N3605 Evolution Adopted 2013-04
N3654 Quoted Strings Library Proposal (Revision 2) Beman Dawes 2013-04-19 2013-05 N3570 Library Adopted 2013-04
N3655 TransformationTraits Redux, v2 Walter E. Brown 2013-04-18 2013-05 N3546 Library Adopted 2013-04
N3656 make_unique (Revision 1) Stephan T. Lavavej 2013-04-18 2013-05 N3588 Library Adopted 2013-04
N3657 Adding heterogeneous comparison lookup to associative containers (rev 4) J. Wakely, S. Lavavej, J. Muñoz 2013-03-19 2013-05 N3465 Library Adopted 2013-04
N3658 Compile-time integer sequences Jonathan Wakely 2013-04-18 2013-05 N3493 Library Adopted 2013-04
N3659 Shared locking in C++ H. Hinnant, D. Vollmann, H. Boehm 2013-04-19 2013-05 N3568 Concurrency  
N3660 User-defined Literals for std::complex, part 2 of UDL for Standard Library Types (version 4) Peter Sommerlad 2013-04-19 2013-05 N3531 Library  
N3661 Digit Separators Lawrence Crowl 2013-04-19 2013-05 N3499 Evolution  
N3662 C++ Dynamic Arrays L. Crowl, M. Austern 2013-04-19 2013-05 N3532 Library Adopted 2013-04
N3663 C++ Sized Deallocation Lawrence Crowl 2013-04-30 2013-05 N3536 Core  
N3664 Clarifying Memory Allocation L. Crowl, C. Carruth, R. Smith 2013-04-19 2013-05 N3537 Core Adopted 2013-04
N3665 Uninterleaved String Output Streaming L. Crowl 2013-04-19 2013-05   Library  
N3666 C++ Latches and Barriers Alasdair Mackintosh 2013-04-18 2013-05 N3600 Concurrency  
N3667 Drafting for Core 1402 Jason Merrill 2012-04-16 2013-05   Core Adopted 2013-04
N3668 exchange() utility function, revision 3 Jeffrey Yasskin 2013-04-19 2013-05 N3608 Library Adopted 2013-04
N3669 Fixing constexpr member functions without const Nicolai Josuttis 2013-04-19 2013-05   Library Adopted 2013-04
N3670 Wording for Addressing Tuples by Type: Revision 2 Mike Spertus 2013-04-19 2013-05 N3584 Library Adopted 2013-04
N3671 Making non-modifying sequence operations more robust: Revision 2 M. Spertus, A. Pall 2013-04-19 2013-05 N3607 Library Adopted 2013-04
N3672 A proposal to add a utility class to represent optional objects (Revision 4) F. Cacciola, A. Krzemieński 2013-04-19 2013-05 N3527 Library Adopted 2013-04
N3673 C++ Library Working Group Ready Issues Bristol 2013 Daniel Krügler 2013-04-19 2013-05 N3522 Library Adopted 2013-04
N3674 C++ Standard Core Language Active Issues, Revision 84 William M. Miller 2013-05-03 2013-05 N3539 Core  
N3675 C++ Standard Core Language Defect Reports and Accepted Issues, Revision 84 William M. Miller 2013-05-03 2013-05 N3540 Core  
N3676 C++ Standard Core Language Closed Issues, Revision 84 William M. Miller 2013-05-03 2013-05 N3541 Core  
N3677 A Proposal to Add additional RAII Wrappers to the Standard Library Andrew L. Sandoval 2013-04-26 2013-05   Library  
N3678 C++ Stream Guards Lawrence Crowl 2013-04-30 2013-05   Concurrency  
N3679 Async() future destructors must wait Hans-J. Boehm 2013-5-05 2013-05   Concurrency  
N3680 Improving pair and tuple Daniel Krügler 2013-04-14 2013-05   Library  
N3681 Auto and braced-init lists Ville Voutilainen 2013-05-02 2013-05   Evolution  
N3682 C++ Standard Evolution Active Issues List (Revision R02) Ville Voutilainen 2013-04-29 2013-05 N3566 Evolution  
N3683 C++ Standard Evolution Completed Issues List (Revision R02) Ville Voutilainen 2013-04-29 2013-05   Evolution  
N3684 C++ Standard Evolution Closed Issues List (Revision R02) Ville Voutilainen 2013-04-29 2013-05 N3567 Evolution  
N3685 string_view: a non-owning reference to a string, revision 4 Jeffrey Yasskin 2013-05-03 2013-05 N3609 Library  
N3686 Traversable arguments for container constructors and methods, wording revision 3 Jeffrey Yasskin 2013-05-03 2013-05 N3513 Ranges  
N3687 C++ Standard Library Active Issues List (Revision R83) Alisdair Meredith 2013-05-06 2013-05 N3522 Library  
N3688 C++ Standard Library Defect Report List (Revision R83) Alisdair Meredith 2013-05-06 2013-05 N3523 Library  
N3689 C++ Standard Library Closed Issues List (Revision R83) Alisdair Meredith 2013-05-06 2013-05 N3524 Library