The Artima Developer Community
Sponsored Link

Articles Forum
A Brief Introduction to Rvalue References

63 replies on 5 pages. Most recent reply: Dec 16, 2014 10:40 AM by Roman L

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 63 replies on 5 pages [ 1 2 3 4 5 | » ]
Frank Sommers

Posts: 2642
Nickname: fsommers
Registered: Jan, 2002

A Brief Introduction to Rvalue References Posted: Mar 10, 2008 4:30 PM
Reply to this message Reply
Advertisement
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 O'Sullivan

Posts: 724
Nickname: vincent
Registered: Nov, 2002

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 3:58 AM
Reply to this message Reply
Just for info: It's a C++ article.

Nemanja Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 8:14 AM
Reply to this message Reply
A very good and informative article. Thanks!

David Clark

Posts: 3
Nickname: davidclark
Registered: Sep, 2007

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 12:47 PM
Reply to this message Reply
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 Dettmer

Posts: 2
Nickname: ddustin
Registered: Mar, 2008

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 5:08 PM
Reply to this message Reply
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 Dettmer

Posts: 2
Nickname: ddustin
Registered: Mar, 2008

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 5:10 PM
Reply to this message Reply
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 mx

Posts: 7
Nickname: darkmx0z
Registered: Mar, 2008

Re: A Brief Introduction to Rvalue References Posted: Mar 11, 2008 5:48 PM
Reply to this message Reply
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 Margaritis

Posts: 674
Nickname: achilleas
Registered: Feb, 2005

Re: A Brief Introduction to Rvalue References Posted: Mar 12, 2008 6:09 AM
Reply to this message Reply
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 Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: A Brief Introduction to Rvalue References Posted: Mar 12, 2008 6:39 AM
Reply to this message Reply
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 Pibinger

Posts: 93
Nickname: rp123
Registered: Jan, 2006

Re: A Brief Introduction to Rvalue References Posted: Mar 12, 2008 3:01 PM
Reply to this message Reply
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 mx

Posts: 7
Nickname: darkmx0z
Registered: Mar, 2008

Re: A Brief Introduction to Rvalue References Posted: Mar 12, 2008 3:31 PM
Reply to this message Reply
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 Nicholson

Posts: 3
Nickname: matman
Registered: Jul, 2005

Re: A Brief Introduction to Rvalue References Posted: Mar 12, 2008 10:20 PM
Reply to this message Reply
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 Trifunovic

Posts: 172
Nickname: ntrif
Registered: Jun, 2004

Re: A Brief Introduction to Rvalue References Posted: Mar 13, 2008 7:43 AM
Reply to this message Reply
Another text on the same topic: http://www.informit.com/guides/content.aspx?g=cplusplus&seqNum=310

Niels Dekker

Posts: 9
Nickname: dekker
Registered: Sep, 2006

Re: A Brief Introduction to Rvalue References Posted: Mar 13, 2008 2:59 PM
Reply to this message Reply
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 Massey

Posts: 2
Nickname: sbmassey
Registered: May, 2006

Re: A Brief Introduction to Rvalue References Posted: Mar 14, 2008 5:26 AM
Reply to this message Reply
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.

Flat View: This topic has 63 replies on 5 pages [ 1  2  3  4  5 | » ]
Topic: Testing Private Methods with JUnit and SuiteRunner Previous Topic   Next Topic Topic: Borachio: Mock Objects for Scala and Android

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use