Explicitly saying ref or out when invoking a function

Lionello Lunesu lionello at lunesu.remove.com
Thu Aug 13 00:25:18 PDT 2009


"Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
news:h5vtj8$1l7b$1 at digitalmars.com...
> Lionello Lunesu wrote:
>>
>> "Andrei Alexandrescu" <SeeWebsiteForEmail at erdani.org> wrote in message 
>> news:h5ttfi$cf3$1 at digitalmars.com...
>>> Lionello Lunesu wrote:
>>>>
>>>> "Jeremie Pelletier" <jeremiep at gmail.com> wrote in message 
>>>> news:h5sl4c$1733$1 at digitalmars.com...
>>>>> It's especially bad since if you modify the function prototype and 
>>>>> change ref, you have all your calls to update too.
>>>>
>>>> That must be the best argument to introduce repeating ref and out!
>>>>
>>>> L.
>>>
>>> // untested
>>> struct Ref(T)
>>> {
>>>     private T* _data;
>>>     this(ref T data) { _data = &data; }
>>>     ref T get() { assert(_data); return *_data; }
>>>     alias get this;
>>> }
>>> Ref!(T) byRef(ref T data)
>>> {
>>>     return Ref!(T)(data);
>>> }
>>>
>>> ...
>>>
>>> void fun(Ref!int rint) { ... }
>>> ...
>>> int x;
>>> fun(byRef(x));
>>
>> Andrei, you bring the compiler vs library discussion to a whole new level 
>> :)
>>
>> We can add "ref" to the list of keywords that can be freed up.
>
> Good point, but actually ref can't be freed, because it would fall prey to 
> infinite regression: if there was no ref keyword, how would you pass by 
> reference the argument to the byRef function?

Uh...... make it an alias parameter and take the address of it? or 
something... Needs IFTI to work nicely with aliases, not sure if it can be 
done..

L.




More information about the Digitalmars-d mailing list