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.
The ability to add new comments in this discussion is temporarily disabled.
Most recent reply: December 16, 2014 10:40 AM by
|
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.htmlWhat do you think of Rvalue references?
|
|
|
Just for info: It's a C++ article.
|
|
|
A very good and informative article. Thanks!
|
|
|
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
|
|
|
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.
|
|
|
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?
|
|
|
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.
|
|
|
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.
|
|
|
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.
|
|
|
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 .
|
|
|
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++.
|
|
|
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.
|
|
|
|
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!
|
|
|
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.
|
|