Article Discussion
A Brief Introduction to Rvalue References
Summary: Rvalue references is a small technical extension to the C++ language. Rvalue references allow programmers to avoid logically unnecessary copying and to provide perfect forwarding functions. They are primarily meant to aid in the design of higher performance and more robust libraries.
64 posts on 5 pages.      
« Previous 1 2 3 4 5 Next »
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: December 16, 2014 10:40 AM by
Frank
Posts: 135 / Nickname: fsommers / Registered: January 19, 2002 7:24 AM
A Brief Introduction to Rvalue References
March 10, 2008 3:30 PM      
Rvalue references allow programmers to avoid logically unnecessary copying and to provide perfect forwarding functions, and are primarily meant to aid in the design of higher performance and more robust libraries. This article discusses this new feature:

http://www.artima.com/cppsource/rvalue.html

What do you think of Rvalue references?
Vincent
Posts: 40 / Nickname: vincent / Registered: November 13, 2002 7:25 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 2:58 AM      
Just for info: It's a C++ article.
Nemanja
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 7:14 AM      
A very good and informative article. Thanks!
David
Posts: 1 / Nickname: davidclark / Registered: September 14, 2007 5:58 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 11:47 AM      
I am not trying to troll here. Basically the problem is the last thing that C++ needs is even more complications, no matter how good the performance is. I have a more complete explanation on my blog:

http://prophipsi.blogspot.com/2008/03/why-i-no-longer-like-or-use-c.html
Dustin
Posts: 2 / Nickname: ddustin / Registered: March 11, 2008 11:05 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 4:08 PM      
This is a great addition. I've always felt the previous solution for these sorts of issues was rather awkward (reverting to pointers) and it had the obvious performance side effects.

This will ofcourse be a hard time for gcc, as the double ampersand is used for goto pointers. A lot of code is likely to break.
Dustin
Posts: 2 / Nickname: ddustin / Registered: March 11, 2008 11:05 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 4:10 PM      
I've read your blog post. It was most unnecessary.

Clearly you do not understand the ramifications of this addition so why clutter the internet with that information?
dark
Posts: 5 / Nickname: darkmx0z / Registered: March 11, 2008 11:38 AM
Re: A Brief Introduction to Rvalue References
March 11, 2008 4:48 PM      
I second Dustin.

David, if you dont like the complexity even if it lets you write more efficent code, then you can skip this extra complexity, its not aimed at you.

C++ was designed to write highly efficent code in a higher, more expressive level than C. In fact, as a replacement for C for most (if not all) tasks. People out there who understand C++ design goals and use it because its the best tool for the job (myself included!) are happy for this extension.
Achilleas
Posts: 98 / Nickname: achilleas / Registered: February 3, 2005 2:57 AM
Re: A Brief Introduction to Rvalue References
March 12, 2008 5:09 AM      
I agree with David Clark. C++ is unnecessarily complex, and with rvalue references it's even more stupidly complex.

First of all, move semantics are silly. C++ is pointer hell, and move semantics make it even more ...hellish. Until now, we had standard rules which allowed us, more or less, to identify where pointers point to (albeit with geometrically progressing difficulty as the code grows). With move semantics, one more complexity order is introduced: we now have to know the internals of the implementation of a class to know how it behaves.

Take, for example, the example shown in the article, about clone ptrs: it demonstrates all the disadvantages of std::auto_ptr, with no advantage whatsoever. If one erroneously access 'p1' instead of 'p2', 'p1' will be null but inside the scope and show the program will erroneously crash.

If I wanted to clone an object, I just clone it. A copy constructor should copy the data. Introducing move semantics in a language with manual memory management is a recipe for disaster.

And the performance gain can be obtained by modifying algorithms. I did not see anything in the article that can't be made with existing C++ with equal performance.

Finally, the problem of lvalues not allowed to be bound to rvalues is simply a language flaw, which could have been dealt with by constructing a local instance of the rvalue and passing it where an lvalue is required. In the example presented, "5" could be replaced by the compiler by an "int temp = 5;", and then passing temp where an lvalue is required.
Nemanja
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: A Brief Introduction to Rvalue References
March 12, 2008 5:39 AM      
May I suggest something?

We all know C++ is complex and there is no need to repeat it in every single C++ related discussion that takes place around.

How about writing an article named "C++ is too complex"?People could pour all their frustrations in one place and give us a break.

Or maybe each C++ article should have a disclaimer in red: "Yes, we already know C++ is complex, so please disregard this fact when discussing the article".

Sorry for the sarcasm, but this is becoming frustrating.
Roland
Posts: 25 / Nickname: rp123 / Registered: January 7, 2006 9:42 PM
Re: A Brief Introduction to Rvalue References
March 12, 2008 2:01 PM      
People who complain about nuisances at least care a little about a thing. Those who don't have abandoned it. BTW, the desired article has been written, see esp. question 3 http://www.bookpool.com/ct/98031 .
dark
Posts: 5 / Nickname: darkmx0z / Registered: March 11, 2008 11:38 AM
Re: A Brief Introduction to Rvalue References
March 12, 2008 2:31 PM      
yet he says:

0. Do you see C++ ever getting simpler? Dropping features, prohibiting co-use of certain features, etc.?
I don't think there is any practical way that C++ can get meaningfully simpler. Any change to the rules of C++ that is not backwards-compatible will face tremendous resistance in the standardization committee, and I think this is proper: it's bad policy to make changes that break programs that are currently legal, and it's even worse for the semantics of legal programs to be modified, i.e., for "silent" changes to be foisted on developers.


Of course C++ could be simpler. If he had all the amount of knowledge we have now back in 1970, Im pretty sure C++ would be way smaller and way simpler it currently is. We could say the same thing about other languages (Java for example, they deprecate huge parts of its standard library without any shame because they add something in the language that outdates the old design). Unless someone comes with a better language (probably a cleaned-up C++ following the same design goals and just taking away some obsolete things from here and there, Java was a failure in that way considering Gosling wanted it to be a C++ replacement but in the end it just came to fill another (actually big) niche) I will still use C++.
Matthew
Posts: 1 / Nickname: matman / Registered: July 26, 2005 11:33 AM
Re: A Brief Introduction to Rvalue References
March 12, 2008 9:20 PM      
In short: Best. Language feature. Ever. I love rvalue references and move semantics. Cleanly passing ownership of some data from one place to another makes me smile.
Nemanja
Posts: 40 / Nickname: ntrif / Registered: June 30, 2004 1:10 AM
Re: A Brief Introduction to Rvalue References
March 13, 2008 6:43 AM      
Another text on the same topic: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=310
Niels
Posts: 9 / Nickname: dekker / Registered: September 7, 2006 6:14 AM
Re: A Brief Introduction to Rvalue References
March 13, 2008 1:59 PM      
I find those rvalue references very interesting. I'm working in the field of medical image processing (www.lkeb.nl), and performance is very much an issue for us. So I expect rvalue references to be very helpful...

Now I wonder, should the next version of the standard library still provide overloads of std::swap for all of the STL containers? It looks like the most generic version, template <class T> swap(T& a, T& b), should be good enough by then!
Steve
Posts: 2 / Nickname: sbmassey / Registered: May 23, 2006 3:21 PM
Re: A Brief Introduction to Rvalue References
March 14, 2008 4:26 AM      
Most new languages over the last couple of decades seem to aspire to be either Smalltalk or Haskell. C++ is the only language whose design is intended to give the developer more control over low level aspects of the machine, while still supporting modern software techniques. It is probably too complex for a lot of uses, but then no other language can distinguish between copying and moving at the language level, as described in the article. Sure, in a Smalltalk-ish language you would implement swap() by switching the references to objects around, but that has the cost of requiring an additional layer of indirection for you to perform the swap. If you need low level efficiency, C++ is a good bet.
64 posts on 5 pages.
« Previous 1 2 3 4 5 Next »