On 10/19/2012 03:26 AM, Malte Skarupke wrote:
On Friday, 19 October 2012 at 00:03:49 UTC, Timon Gehr wrote:

Const is different in D and in C++. Relating const and rvalues is
arbitrary and does not make a lot of sense.

Regarding 'in ref'/'scope ref': What should 'scope' apply to in

void foo(scope ref int* x);

Not sure what you mean with "relating." I'm not making any claims about
there being a relationship between rvalues and constness.


You do it again right away:

This is about finding a way that you can define a function which safely
accepts lvalues and rvalues without having to make a copy. If we specify
the argument as "ref in", then we can safely pass for example the number
                  ^~~~~~~~
                    const
5 to it.
  ^
rvalue

And this would never break existing code, so that something
like swap(5, 4) would never be possible code.


That does not break existing code except code that checks validity of
code, but every language change does that.

For the example that you gave you'd be unable to store the address of x.
So doing

int** storage;
void foo(scope ref int * x)
{
     storage = &x;
}

would be illegal.


Then how to specify that the value of x cannot be escaped?
I'm in favour of doing it the other way round and disallow escaping of
ref parameters without an unsafe cast.

@jerro: the same thing: I'm not trying to fix the problem that you
mention. I'm trying to define a function which can safely accept rvalues
and lvalues without having to make a copy.

Reply via email to