rvalue references

Manu turkeyman at gmail.com
Thu Apr 25 21:15:07 PDT 2013


On 26 April 2013 08:36, Jonathan M Davis <jmdavisProg at gmx.com> wrote:

> On Wednesday, April 24, 2013 08:54:09 Zach the Mystic wrote:
> > On Wednesday, 24 April 2013 at 02:56:42 UTC, Jonathan M Davis
> >
> > wrote:
> > > So, probably the best route at this point is to come up with a
> > > new attribute
> > > which is replace with ref in the function definition and
> >
> > When you say "replace with ref", does that mean 'ref' won't
> > appear in the common case?
> >
> > ref T fc(scope int a) {}
> >
> > The problem would be that 'scope' would behave differently,
> > implying 'ref' with a value type, from with a reference type, in
> > which it shouldn't imply 'ref'. I don't know if it makes sense to
> > automatically promote the meaning of 'scope' to include 'ref' for
> > value types while leaving it alone for reference types. This was
> > objected to by others, but if it were provably harmless to allow,
> > it would be an appearance improvement.
>
> You misunderstand me (possibly because I didn't proofread what I wrote).
> What
> I mean is that the way that auto ref should work with non-templated
> functions
> is that
>
> auto foo(auto ref T param) {...}
>
> becomes
>
> auto foo(ref T param) {...}
>
> underneath the hood. Then when you pass an rvalue to it - e.g. foo(T(5)) -
> that gets translated to something like
>
> T __temp = T(5);
> foo(__temp);
>
> Then auto ref works with both lvalues and rvalues with only one function
> definition, and ref is unchanged in how it works (it still only accepts
> lvalues).
>

Why bother with 'auto'? Why not just make this default behaviour?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.puremagic.com/pipermail/digitalmars-d/attachments/20130426/69b48866/attachment-0001.html>


More information about the Digitalmars-d mailing list