June 20, 2012 [dmd-internals] New 'auto ref' that can receive both lvalue and rvalue | ||||
---|---|---|---|---|
| ||||
In 2.059, struct literal has been changed to rvalue. But to avoid breaking existing codes, we decided to introduce 'rvalue reference' that allows to receive struct literals with 'ref' parameter. But, it does not have enough consensus. - In 2.058 and earlier, the 'ref' parameters can receive only lvalues, and non-ref ones can receive only rvalues. But the 'rvalue reference' did break the consistency. - We should allow to bind other rvalues (non struct literals, returned values from non ref function) with 'ref' parameter? - Getting rvalue reference with mutable ref is almost useless. Instead, we should use `const ref` for rvalue reference? On the other hand, current D has 'auto ref' parameter, but it works only with the combination of template function and IFTI. (If you instantiate such template function explicitly, 'auto ref' parameter will raise an error. See http://d.puremagic.com/issues/show_bug.cgi?id=8204) I think we should introduce new 'auto ref' parameter. That: - receives both lvalues and rvalues. If rvalue is given, new 'auto ref' binds it to temporary variable in the caller, and get its reference. - works for template and non template functions. For the template function, it will instantiate only one function body. An experimental implementation of my proposal: https://github.com/D-Programming-Language/dmd/pull/1019 It will break existing codes (e.g. We should change opEquals signatures, from 'const ref' to 'auto ref'), but it will increase orthogonality of language. Regards. Kenji Hara _______________________________________________ dmd-internals mailing list dmd-internals@puremagic.com http://lists.puremagic.com/mailman/listinfo/dmd-internals |
Copyright © 1999-2021 by the D Language Foundation