Move Constructors - Converting Lvalues to Rvalues
RazvanN
razvan.nitu1305 at gmail.com
Fri Oct 4 07:15:44 UTC 2024
On Thursday, 3 October 2024 at 15:35:36 UTC, Walter Bright wrote:
> What if you have:
> I'm also currently struggling with:
> ```
> this(S);
> this(ref S);
> ```
> and then trying to get "is it copyable" to work. The trouble is
> that a move constructor not only has an S for an rvalue, that S
> must also be the same as the struct name. This cannot be
> determined by the parser, it needs semantic analysis. This
> means that when the constructor is searched for, it has to
> exclude matching on a move constructor, that cannot be detected
> before semantic analysis.
You can avoid this by simply moving the move and copy constructor
to
different overload sets during semantic analysis (__ctor,
__cpctor, __mvctor).
This will simplify the code immensely and it also has the added
benefit that
move and copy constructor will not be considered for manual
constructor calls,
which makes sense because mv and cp ctor are not meant for that.
More information about the Digitalmars-d
mailing list