Parameter forwarding
Paul Backus
snarwin at gmail.com
Thu Oct 14 17:37:21 UTC 2021
On Thursday, 14 October 2021 at 16:53:17 UTC, Kostiantyn Tokar
wrote:
> Take a look at `Tuple`
> [constructor](https://github.com/dlang/phobos/blob/4130a1176cdb6111b0c26c7c53702e10011ff067/std/typecons.d#L672).
> ```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