View mode: basic / threaded / horizontal-split · Log in · Help
January 17, 2012
Re: Call site 'ref'
2012/1/17 Mehrdad <wfunction@hotmail.com>:
> ?!?!?
>
> Documentation is frequently out of date, but code isn't.
> And ideally, the code wouldn't NEED documentation, BECAUSE it SAYS what it's
> doing.

Maybe - if you have access to function's source text. But we were
talking about a specific feature on callers side. "ref" stated at call
site doesn't say what function is doing, it only tells that function
returns one of it's results in specific parameter. That might be
occasionally useful, but it is not worth extra syntax it introduces.
January 17, 2012
Re: Call site 'ref'
On 15/01/2012 14:12, Peter Alexander wrote:
<snip>
> I agree with requiring ref at the call site in principle, although it would be too much of
> a breaking change to introduce now. Perhaps allow it, and issue a warning if not used?

Maybe phase it in in this sequence:

1. Allow ref/out at call site.
2. Add a warning for if ref/out at call site is omitted.
3. Deprecate omitting ref/out at call site.
4. Require ref/out at call site.
5. Allow overloading of functions based on parameter storage class, as much as makes sense.

Stewart.
January 18, 2012
Re: Call site 'ref'
On 1/15/12 7:21 PM, Timon Gehr wrote:
> On 01/16/2012 02:00 AM, Andrei Alexandrescu wrote:
>> On 1/15/12 6:38 PM, Timon Gehr wrote:
>>> On 01/16/2012 01:35 AM, Andrei Alexandrescu wrote:
>>>> On 1/15/12 6:30 PM, Peter Alexander wrote:
>>>>> On 15/01/12 11:56 PM, Jonathan M Davis wrote:
>>>>>> On Monday, January 16, 2012 00:41:14 Timon Gehr wrote:
>>>>>>> Well, struct literals are lvalues, at least in DMD.
>>>>>>
>>>>>> Yeah. I don't understand that. I've argued about it with Walter
>>>>>> before.
>>>>>> Apparently they are in C++ as well. I don't understand it. It
>>>>>> makes it
>>>>>> so that
>>>>>
>>>>> In C++, struct literals are rvalues. C++ just has a special rule that
>>>>> const references can bind to rvalues (but non-const references
>>>>> cannot),
>>>>
>>>> That's a bad rule that we shouldn't copy.
>>>>
>>>> Andrei
>>>
>>> What do you think is an optimal rule regarding struct
>>> literals/lvalues/rvalues and ref parameters?
>>
>> auto ref
>>
>> Andrei
>
> But that only works for templates?

For non-templates, if it's important to distinguish between lvalues and 
rvalues, use two overloads.

Andrei
January 18, 2012
Re: Call site 'ref'
On 01/18/2012 06:13 PM, Andrei Alexandrescu wrote:
> On 1/15/12 7:21 PM, Timon Gehr wrote:
>> On 01/16/2012 02:00 AM, Andrei Alexandrescu wrote:
>>> On 1/15/12 6:38 PM, Timon Gehr wrote:
>>>> On 01/16/2012 01:35 AM, Andrei Alexandrescu wrote:
>>>>> On 1/15/12 6:30 PM, Peter Alexander wrote:
>>>>>> On 15/01/12 11:56 PM, Jonathan M Davis wrote:
>>>>>>> On Monday, January 16, 2012 00:41:14 Timon Gehr wrote:
>>>>>>>> Well, struct literals are lvalues, at least in DMD.
>>>>>>>
>>>>>>> Yeah. I don't understand that. I've argued about it with Walter
>>>>>>> before.
>>>>>>> Apparently they are in C++ as well. I don't understand it. It
>>>>>>> makes it
>>>>>>> so that
>>>>>>
>>>>>> In C++, struct literals are rvalues. C++ just has a special rule that
>>>>>> const references can bind to rvalues (but non-const references
>>>>>> cannot),
>>>>>
>>>>> That's a bad rule that we shouldn't copy.
>>>>>
>>>>> Andrei
>>>>
>>>> What do you think is an optimal rule regarding struct
>>>> literals/lvalues/rvalues and ref parameters?
>>>
>>> auto ref
>>>
>>> Andrei
>>
>> But that only works for templates?
>
> For non-templates, if it's important to distinguish between lvalues and
> rvalues, use two overloads.
>
> Andrei

Currently 'auto ref' gives a compile error if used in a non-templated 
function parameter list. What are the semantics of 'auto ref' you have 
in mind? Are they specified somewhere?
January 18, 2012
Re: Call site 'ref'
On 1/18/12 11:27 AM, Timon Gehr wrote:
> On 01/18/2012 06:13 PM, Andrei Alexandrescu wrote:
>> For non-templates, if it's important to distinguish between lvalues and
>> rvalues, use two overloads.
>>
>> Andrei
>
> Currently 'auto ref' gives a compile error if used in a non-templated
> function parameter list. What are the semantics of 'auto ref' you have
> in mind? Are they specified somewhere?

I meant two overloads that don't use auto ref:

void fun(S);
void fun(ref S);


Andrei
Next ›   Last »
1 2 3 4 5
Top | Discussion index | About this forum | D home