Archive for April 2009
C++0x: Do people understand rvalue references?
[last update: 2009-05-27]
Occasionally I happen to see a piece of C++ code from an eager author that tries to utilize rvalue references but doesn’t understand them and gets it wrong. I remember that I had trouble fully grasping the rvalue reference concept. But now, it seems like that was way in the past. I can hardly remember why it was so difficult to understand rvalue references.
It may have something to do with the sources people use to learn about this feature. For example I wouldn’t consider the C++0x wikipedia article to be a good introduction for rvalue references. It seems too short for that. But this wikipedia article is a nice overview of what kind of features can be expected.
Let me just mention the real sources worth reading:
- N1377: Move Proposal (2002)
- N1385: Perfect Forwarding Problem (2002)
- N2027: A Brief Introduction to Rvalue References (2006)
- N2812: A Safety Problem with Rvalue References (2008)
- N2844: Fixing a Safety Problem with Rvalue References (Revision 1, 2009)
- Rvalue References 101by Dave Abrahams
I would recommend N2027 as an introduction and Dave Abraham’s article for more practical details including exception safety and return value optimizations.