Move Constructor Syntax
H. S. Teoh
hsteoh at qfbox.info
Tue Oct 8 00:48:17 UTC 2024
On Tue, Oct 08, 2024 at 12:31:44AM +0000, Salih Dincer via Digitalmars-d wrote:
> On Monday, 7 October 2024 at 18:04:58 UTC, H. S. Teoh wrote:
> >
> > What about:
> >
> > this(~T t)
> >
> > The ~ being an allusion to ~this, the idea being that after the move the
> > operand t will effectively have been destructed and invalid.
>
> Before you decide that, consider how often we use the ~ symbol. But isn't
> this (option 2) more meaningful?
>
> **this**(**=MyStruct** name) { ... }
Using = in this case is an exceptionally ugly visual clash with default
parameters. Imagine monstrosities like:
this(=T t=T(1));
Ick.
This looks better:
this(~T t=T(1));
> **The ~ Symbol in D**
>
> * String/Array concatenation
> * Bitwise complement
> * Dynamic expanding array
> * Destructuring functions
> * Exclusive operator with opOpAssign
[...]
Since the move ctor name is `this`, the use of `~` immediately reminds
one of the dtor `~this`. One doesn't normally associate ctors with
array concatenation or bitwise complement, so the use of `~` would seem
to be the more intuitive meaning in the move ctor, which would be
spelled `this(~T t)`.
T
--
Did you hear about the monkeys who shared an Amazon account? They were Prime mates!
More information about the Digitalmars-d
mailing list