Parameter forwarding

Paul Backus snarwin at
Thu Oct 14 17:37:21 UTC 2021

On Thursday, 14 October 2021 at 16:53:17 UTC, Kostiantyn Tokar 
> Take a look at `Tuple` 
> [constructor](
> ```d
> this(Types values)
> {
>     field[] = values[];
> }
> ```
> Actual fields are constructed from lvalues. Why there is no 
> `auto ref` and `forward`? It looks like there is no way to 
> construct a tuple without copying.

Poor test coverage. If you go through Phobos and test everything 
with a non-copyable struct (`@disable this(this)`), you will find 
that most templates (including `Tuple`) fail to compile. It is 
simply a case that the authors of the code never considered.

> So is there no way to utilize move semantics using Phobos? Why 
> forwarding is so neglected?

I suspect it is neglected because nobody wants to volunteer for 
the tedious work of going through Phobos, adding unit tests that 
check for unnecessary copies, and inserting `auto ref` and 
`forward` in the appropriate places.

More information about the Digitalmars-d-learn mailing list