June 2014

Quick Q: When are copy and move operations automatically generated?—StackOverflow

Recently on SO:

What are the rules for automatic generation of move operations?

In C++98, the C++ compiler could automatically generate copy constructor and copy assignment operator via member-wise copy, e.g.

struct X {
    std::string s;
    std::vector<int> v;
    int n;

The compiler automatically generates copy constructor and copy assignment operator for X, using member-wise copy.

But how do things change in C++11 with move semantics?

Are the move constructor and move assignment operator automatically generated, like copy constructors and copy assignment operators?

Are there cases in which move operations are not automatically generated?

The Drawbacks of Implementing Move Assignment in Terms of Swap—Scott Meyers

Hot off the Meyers press: How would you implement move, and why? Scott Meyers explains two related issues:

The Drawbacks of Implementing Move Assignment in Terms of Swap

by Scott Meyers

From the article:

More and more, I bump into people who, by default, want to implement move assignment in terms of swap. This disturbs me, because (1) it's often a pessimization in a context where optimization is important, and (2) it has some unpleasant behavioral implications as regards resource management.

CppCon Status Update, Second Keynote—Boris Kolpackov

CppCon has announced a second keynote: C++ on Mars by Dr. Mark Maimone, JPL's lead architect for the C++ self-driving software in Mars Rover Curiosity and other rovers. He will be speaking on what it took to use C++ in this environment, and how this experience and lessons learned apply to other projects. This is a real treat you will not want to miss. More details below...

But first, a note: The full conference program is still coming soon, but its publication has been slightly delayed because the Program Committee had an unexpectedly high workload -- there were nearly twice as many talk proposals submitted as the conference has room for. Even though CppCon 2014 will have six full-week tracks with a total of 100 sessions, the PC had to make the difficult choice to reject many good talks that just didn't fit -- so many, in fact, that the good turned-down talks could fill another four-track full-week conference by themselves. (The silver lining is that the PC may have a head start on the program of CppCon 2015...)

If you haven't registered, register today -- Early Bird Registration ends in just over a week.

Status Update, Second Keynote

by Boris Kolpackov

From the announcement:

There are several developments in preparation for the conference: We’ve sent the acceptance notifications to authors who proposed talks. If you haven’t received the email, please contact the Program Committee. The Program Committee is now hard at work putting together and scheduling the program and we still aim to have it ready by the 27th of June. Note also that the early bird deadline is only 9 days away. Finally, we have the second keynote for CppCon 2014:

C++ on Mars: Incorporating C++ into Mars Rover Flight Software

by Dr. Mark Maimone

One of the more challenging aspects of developing flight software (FSW) for NASA’s Spirit and Opportunity Mars Exploration Rovers (MER) and Curiosity, the Mars Science Laboratory rover was how to enable them to drive themselves safely through unknown Martian terrain. When the MER mission was approved in the year 2000, JPL researchers had already demonstrated that capability on prototype rovers using software written primarily in C++ on a VxWorks realtime O/S platform with shared memory. So when asked to incorporate that capability into the MER vehicles which also relied on a similar VxWorks realtime O/S, the team concluded it would be safest and most expedient to incorporate the already field-tested C++ software. But that presented a challenge, since at that point all rover FSW development was mandated to be done mainly in the C programming language.

In this talk we present some of the challenges we faced and solutions we found in deploying C++ onto the Mars Rovers. For example, dynamic allocation was initially precluded, but development of a specialized memory allocator (using the C++ “placement new” operator) enabled us to incorporate it safely into the flight system. We will discuss what aspects of C++ were incorporated, what simulation environments aided development, describe some of the tools used to validate system behavior, and explain how our success using C++ for the implementation of autonomous navigation on MER has influenced future FSW efforts.

Speaker’s bio: Dr. Mark Maimone is a Navigation and Machine Vision researcher at JPL. Mark designed and developed the autonomous vision and navigation software that lets the MER and MSL Mars Rovers drive themselves safely, and wrote ground software that automated the analysis of Mobility and arm operations on MER. Mark is now a Rover Driver for Curiosity, and he continues to develop and enhance the onboard autonomous vision and navigation software for the rovers. Mark earned his Ph.D. in Computer Science at Carnegie Mellon University in 1996, and completed a postdoc there in 1997 as Navigation and Software Lead for the 1997 Atacama Desert Trek. At JPL since 1997, Mark has also worked on the Long Range Science Rover, Planetary Dexterous Manipulator, and Pioneer Vision System for Chornobyl Inspection projects, delivering 3D vision systems for autonomous robotic operations and mapping.

Effective Modern C++ due October, preview in early July—Scott Meyers

Scott Meyers' highly anticipated new book Effective Modern C++ is on the way:

Effective Modern C++ Status Report

by Scott Meyers

From the announcement:

In recent days, two major milestones for Effective Modern C++ have been achieved. First, I sent a draft of the book's Introduction out for technical review. That was the last part of the book to be written, so I finally have a full draft manuscript. Second, I received an image of the book cover from my publisher, so I now know what the book will look like.


  • Early October: Digital versions of the book become available.
  • Late October: Print versions of the book become available.

If you're dying to see what's in the book, and you don't mind dealing with a manuscript that's in draft form (and hence contains technical errors, awkward prose, Item titles in need of revision, primitive diagrams, confusing explanations, and, I hope, some stuff in decent shape), Effective Modern C++ will be part of O'Reilly's Early Release Program, meaning you'll have a chance to see the book in the same form as my technical reviewers. You'll also be able to offer comments on it. As things stand now, the book is slated to be available in Early Release form the week of July 7th.

Why C++ Sails When the Vasa Sank—Scott Meyers

Now available online, a nice talk by Scott Meyers about why modern C++ is alive and continues to enjoy life and growth:


Why C++ Sails When the Vasa Sank

by Scott Meyers

The Vasa was a 17th-century Swedish warship which suffered such feature creep during construction that it sank shortly after leaving the harbour on its maiden voyage. In the early 1990s, the C++ standardisation committee adopted the Vasa as a cautionary tale, discouraging prospective language extensions with "Remember the Vasa!" Yet C++ continued to grow, and by the time C++ was standardised, its complexity made the Vasa look like a rowboat.

The Vasa sank, however, while C++ cruised, and it looks likely to continue doing so even as the latest revised standards (C++11 and C++14) add dozens of new features, each with its own idiosyncrasies. Clearly, C++ has gotten some important things right. In this talk, Scott Meyers considers the lessons to be learned from the ongoing success of a complex programming language that's over 30 years old, yet very much alive and kicking.

Using variadic macros—Andrzej Krzemieński

The latest from the desk of Andrzej:

Using variadic macros

by Andrzej Krzemieński

From the article:

But what struck me was something different. Why is it only some compilers that rejected my code. Why did most of the other compilers accept my apparently buggy code and produced the right result?

The answer is in the title of this post. Boost.StaticAssert is clever and wherever possible it uses variadic macros. ... it is now OK: all these arguments along with the separating commas are forwarded further (e.g., to static_assert) to the code that knows how to interpret these tokens. This is a very nice usage of variadic macros.

CppCon Program Preview, 6 of N—Boris Kolpackov

cppcon-081.pngMore CppCon 2014 accepted talks have just been announced, below. For past announcements about the conference program, see also:

Early Bird registration is available until June 30.


CppCon Program Preview, 6 of N

by Boris Kolpackov

From the announcement:

Stefanus Du Toit: “Hourglass Interfaces for C++ APIs”
Pedro Ramalhete, Andreia Correia: “How to Make Your Data Structures Wait-Free for Reads”
Gor Nishanov: “await 2.0: Stackless Resumable Functions”
Fedor Pikus: “Where did My Performance Go? (Scaling Visualization in Concurrent C++ Programs)”
Łukasz Mendakiewicz: “Viewing the World Through Array-Shaped Glasses”


Stefanus Du Toit: “Hourglass Interfaces for C++ APIs”

C++ provides a much richer set of abstractions than C. Classes, templates, overloading, and other core C++ features can be leveraged for more readable syntax, better compile time typechecking, more open ended genericity and improved modularity. On the flip side, C89 still boasts some advantages over C++, especially when viewed through a pragmatic lens. C ABIs on many platforms have been stable for decades, practically every language supports binding to C code through foreign function interfaces, and including nearly any C89 header has a negligible effect on compile time on modern computers. The Hourglass pattern provides the best of both worlds. It’s a way to structure libraries that retains the pragmatic benefits of C89 while still providing C++’s richness both at an interface and implementation level. It makes providing bindings from other languages to C++ libraries easier, and insulates from ABI issues such as incompatibilities between debug and release variants of runtimes. This talk provides an overview of the pattern, teaches practical techniques for its implementation using C++98 and C++11, and shares experience from using the pattern in real world projects.

Speaker’s bio: Stefanus Du Toit is a Software Lead at Thalmic Labs, where he enables amazing gestural experiences using the Myo armband. Stefanus previously worked as a Software Architect and Software Development Manager at Intel Corporation, and co-founded RapidMind (acquired by Intel), a startup that targeted GPUs and other processors using standard C++. Stefanus served on the C++ standards committee as Project Editor for C++14 and as Committee Secretary. He lives in Kitchener-Waterloo, Ontario, Canada and holds a BMath CS from the University of Waterloo.


Pedro Ramalhete, Andreia Correia: “How to Make Your Data Structures Wait-Free for Reads”

In this talk we will describe a new concurrency control algorithm with Blocking write operations and Wait-Free Population Oblivious read operations, which we named the Left-Right algorithm. We will show a new pattern where this algorithm is applied, which requires using two instances of a given resource, and can be used for any data structure, allowing concurrent access to it similarly to a Reader-Writer lock, but in a non-blocking manner for reads, including safe memory management without needing a GC.

Speaker’s bio: Pedro Ramalhete has a PhD in Particle Physics for research done at CERN. Most of the research itself required programming in C++, and he also had a major participation in the coding of the experiment’s data acquisition and decoding software in C and C++. Pedro is currently working at Cisco writing networking software, with emphasis on real-time concurrent synchronization techniques, and wait-free/lock-free data structures.


Gor Nishanov: “await 2.0: Stackless Resumable Functions”

When dealing with the task/future based asynchronous model, developers need to write lambda-heavy continuation code with potentially multiple nesting lambdas. This makes the code less readable and not very pleasant to write. Stackless resumable functions allow developers to use more natural imperative coding style and provide performance benefits that are not possible with library-only solutions.

Speaker’s bio: Gor Nishanov is a Principal Software Design Engineer on the Microsoft C++ team. He works on the ‘await’ feature. Prior to joining the C++ team, Gor was working on distributed systems in Windows Clustering team.

Fedor Pikus: “Where did My Performance Go? (Scaling Visualization in Concurrent C++ Programs)”

High performance is one of the main reasons programmers choose C++ for their applications. If you are writing in C++, odds are you need every bit of computing power your hardware can provide. Today, this means writing multi-threaded programs to effectively utilize the multiple CPU cores that the hardware manufacturers keep adding. Everyone knows that writing multi-threaded programs is hard. Writing correct multi-threaded programs is even harder. Only after spending countless hours debugging race conditions and weird intermittent bugs do many programmers learn that writing efficient multi-threaded programs is harder yet. Have you ever wanted to see what are all your threads doing when they should be busy computing? This talk will show you how. We begin by studying several techniques necessary for collecting large amounts of data from the running program very efficiently, with little overhead and minimal disruption to the program itself. We will cover efficient thread-safe memory management and efficient thread-safe disk I/O. Along the way we dabble in lock-free programming just enough to meet our needs, lest the subject will spiral into an hour-long talk of its own. With all these techniques put together, we can collect information about what each thread is doing, which threads are computing and what exactly, and which threads are slacking off waiting on locks, and do it at the time scale of tens of microseconds if necessary. Then we process the collected data and create a timeline that shows exactly what the program was doing at every moment in time.


Łukasz Mendakiewicz: “Viewing the World Through Array-Shaped Glasses”

It’s agreed among experts that the most performant data structure in C++ is an array. Or a vector. Or a dynarray. Indeed, until recently there was no standardized approach in C++ to view these types in a uniform manner. It was even murkier when the data had logically more than one dimension. This talk is an introduction to the new features proposed for C++17 in N3851 bringing all contiguous data into harmony and lifting it to higher dimensions: index, bounds, array_view and more. Attendees will also learn how indexable algorithms differ from the traditional elemental ones, and what does it mean for parallelism.

Speaker’s bio: Łukasz Mendakiewicz is a software engineer at Microsoft, where he focuses on the customer experience with parallel programming models for C++. He is especially interested in GPGPU acceleration, and puts this passion to work on C++ AMP. He holds an M.S. in Computer Science from AGH UST in Krakow, Poland.

Masking a Class in Boost Graph, Part 3: Finding the Path—Vadim Androsov

Part 3 of Vadim's experience report about using Boost's graph support in an existing game app:

Masking a Class in Boost Graph. Part 3: Finding the Path

by Vadim Androsov

From the article:

In the previous articles of the series we’ve reviewed the adaptive process of the square game field for concepts of boost graphs. Now we’ll consider the process of finding the path in the square field. Implementation of boost search allows adapting the algorithm quite accurately. In this article we’ll provide just one example of such parameterization – an ability to create various lengths of graph edges. ...