Using in as a parameter qualifier
Jonathan M Davis
jmdavisProg at gmx.com
Fri May 31 18:15:17 PDT 2013
On Saturday, June 01, 2013 05:11:44 Shriramana Sharma wrote:
> On Fri, May 31, 2013 at 8:55 PM, Jonathan M Davis <jmdavisProg at gmx.com>
wrote:
> > In D, const ref does not accept rvalues (unlike C++'s const &).
>
> So what is the syntax that accepts rvalues and yet does not make a
> copy of the input object?
If you have a templated function, you can use auto ref
auto foo(T)(auto ref T var) {..}
or if you don't want to templatize the type but just the function:
auto foo()(auto ref T var) {...}
For non-templated functions, there currently is no solution. You're forced to
duplicate the function. Various options are under discussion, and it's likely
that auto ref will be used but with slightly different semantics (auto ref on
templated functions actually results in two functions - one with ref and one
without - and that won't work with non-templated functions). But that hasn't
been agreed upon yet. We _will_ have a solution, but it's a hot topic that's
still under debate. For various technical reasons, we won't go the C++ route
of having const ref accept rvalues (which is usually what people suggest), but
we will have a solution relatively soon as there's a fair bit of pressure to
resolve the problem.
- Jonathan M Davis
More information about the Digitalmars-d-learn
mailing list