|
Re: A Brief Introduction to Rvalue References
|
Posted: Mar 12, 2008 6: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.
|
|