Discussion: Rvalue refs and a Move construtor for D

Suleyman sahmi.soulaimane at gmail.com
Wed Sep 4 14:45:38 UTC 2019


On Wednesday, 4 September 2019 at 09:22:09 UTC, a11e99z wrote:
> [...]
> let's see C++ copy constructor
>> Point( const Point& rhs ) { ... } // const ref to A. that all
>
> let's D copy constructor
>> this( ref return scope const Point rhs ) { ... } // const.. 
>> ref to.. WTF?

I feel ya.

> another side is move constructor. C++ again:
>> Data( Data&& rhs ) { ... } // even less chars than for copy.
>          // && - either logical AND or move semantics. u can't 
> mistake.
> D?
>> this( @rvalue Data rhs ) @move { ... }
> 3.14dec!
> it even doesn't like to copy constructor - related entities.

relax, it's going to be either way with `@rvalue` or with `@move` 
not with both.

> most people I think come to D from C++ or they tried C++ and 
> faced with something incomprehensible, ambiguous, complex.
> (it seems to me that the templates are too sophisticated, and 
> in D templates are understandable with constraints it even 
> easier.)
> and they come to D cuz many people said on any forums "try to 
> use D that has advantages over <lang>".
> and people try to write easy entity like "Point" and see.. this 
> - copy/move..
> it looks like fraud.
> its not easy to understand, u just can not step into D by soft 
> step, u should read half specification to understand clear, 
> simple things that is not clear and looks not simple.
>
> please hold things easy. I don't know how, but keep a easy way.

Well C++ rvalue ref is not easy to understand either. If we go 
the @rvalue ref way it's going to be the same. If we go the @move 
way then if you can understand the copy constructor, the @move 
attributes simply denotes the move version of the copy 
constructor. If you don't understand the difference between move 
and copy then you don't need to use it and it won't come in your 
way until you do.




More information about the Digitalmars-d mailing list