C++ Rvalue References Explained--Thomas Becker

What are rvalue references and move semantics, and how do they work again, exactly?

If you haven't read Thomas Becker's nice explanation (or even if you have), be sure to check it out:

C++ Rvalue References Explained

Thomas Becker

1. Introduction
2. Move Semantics
3. Rvalue References
4. Forcing Move Semantics
5. Is an Rvalue Reference an Rvalue?
6. Move Semantics and Compiler Optimizations
7. Perfect Forwarding: The Problem
8. Perfect Forwarding: The Solution
9. Rvalue References and Exceptions
10. The Case of the Implicit Move
11. Acknowledgments and Further Reading

Parameter Types in Constructors -- Scott Meyers

From the keyboard of Scott Meyers:

Parameter Types in Constructors

by Scott Meyers

I recently went through Sumant Tambe's presentation materials from his Silicon Valley Code Camp presentation, "C++11 Idioms."  He argues that an emerging idiom is to pass arguments to constructors by value, because this takes advantage of move opportunities when they are available.

I was surprised to read about this emerging idiom, in part because I had not heard of it (I'm supposed to be clued in about this kind of stuff) and in part because it runs contrary to my own thinking on the subject, which is to use perfect forwarding...

Universal References in C++11 -- Scott Meyers

Recorded live at C++ and Beyond 2012:

Universal References in C++11

Scott Meyers

Given that rvalue references are declared using "&&", it seems reasonable to assume that the presence of "&&" in a type declaration indicates an rvalue reference. That is not the case...

In this article, I describe the two meanings of "&&" in type declarations, explain how to tell them apart, and introduce new terminology that makes it possible to unambiguously communicate which meaning of "&&" is intended. Distinguishing the different meanings is important, because if you think "rvalue reference" whenever you see "&&" in a type declaration, you'll misread a lot of C++11 code...

Poll: Portland attendees and subgroups

If you are planning to attend the Portland meeting, please fill out this brief poll to help us allocate rooms and plan for the week. Thanks!

 

 

Using Strings in C++ Template Metaprograms -- Abel Sinkovics and Dave Abrahams

Fresh off the press at C++ Next:

Using strings in C++ template metaprograms

by Abel Sinkovics and Dave Abrahams

Of all the reasons to love metaprogramming, probably the most compelling is that it lets us embed “little languages” in our programs... Instead of C++ expressions, of course, strings could be used to represent the DSL code snippet in the embedding C++ code. In fact, that’s an approach used by many “traditional” libraries:

auto all_caps = std::regex("[A-Z]+"); // OK

The only problem is, the contents of that string are only known at runtime, which means the language has to be interpreted at runtime, and we lose the benefit of being able to translate the structure into compiled code. The “delayed evaluation” has been delayed too long.

If, however, these strings could be parsed at compile-time, the resulting programs could have optimal performance again...

[more]

Unifying Generic Functions and Function Objects -- Dave Abrahams

From Dave Abrahams:

Unifying Generic Functions and Function Objects

I just got finished collaborating on a proposal with Faisal Vali and Herb Sutter to include generic lambdas and pythy functions in the core language. After the upcoming Portland committee meeting, we should have a good sense of how much appetite there is on the committee for including these features in C++.

While we were writing that paper, we got some of our most helpful comments and insights from Mathias Gaunard. It was a pivotal moment when Mathias reminded us that we could create operator overload sets explicitly with inheritance and using declarations, and then used it to demonstrate "overloaded lambda expressions..."

[more]

 

Padding and Rearranging Structure Members -- Dan Saks

Hot of the press at Dr. Dobb's:

Padding and Rearranging Structure Members

By Dan Saks

... Multibyte objects often have an alignment ... a "requirement that objects of a particular type be located on storage boundaries with addresses that are particular multiples of a byte address". The Standard leaves it up to each target processor to specify its alignment requirements. That is, a processor might require that a 4-byte integer or pointer referenced as a single object be word aligned — at an address that's a multiple of four. A processor also might require that an 8-byte floating-point number be word aligned, or maybe even double-word aligned — at an address that's a multiple of eight.

According to the C Standard, a program that attempts to access an improperly aligned object produces undefined behavior. This means that the program is in error, but the exact consequences of that error are platform-dependent. With many processors, an instruction that attempts to access improperly aligned data issues a trap. With other processors, an instruction that accesses misaligned data executes properly but uses up more cycles to fetch the data than if the data were properly aligned...

[more]

Casablanca: C++ on Azure -- John Azariah and Mahesh Krishnan

Casablanca is a Microsoft incubation effort to support cloud-based client-server communication in native code using a modern asynchronous C++ API design. Think of it as Node.js, but using C++ -- from simple services, to JSON and REST, to Azure storage and deployment, and more.

Casablanca gives you the power to use existing native C++ libraries and code to do awesome things on the cloud server. In this talk from TechEd Australia, John Azariah and Mahesh Krishnan show how it's done.