`ref T` should be a type!!

bauss jj_1337 at live.dk
Fri Mar 29 21:24:54 UTC 2019


On Friday, 29 March 2019 at 20:49:20 UTC, Victor Porton wrote:
> On Friday, 29 March 2019 at 16:18:59 UTC, Alex wrote:
>> On Friday, 29 March 2019 at 16:06:09 UTC, Victor Porton wrote:
>>> That `ref T` (where T is a type) is not a type is a serious 
>>> design error, because so `ref T` cannot be used as a template 
>>> argument.
>>>
>>> It is a very serious problem.
>>>
>>> Even in C++ despite of all its silliness, T& is a type and 
>>> can be used as a template argument.
>>>
>>> Can the language be changed to resolve this problem?
>>
>> Could you show an example, where an alias parameter is not 
>> enough?
>
> The following does not work:
>
> class C(alias T) { }
> C(ref int) a;

Why do you expect it to work? What exactly are you supposed to do 
with that?

ref can only be used as parameters and thus it would only ever 
work like:

class C(alias T)
{
     void foo(T bar) { ... }
}
C!(ref int) baz;

Which is just ugly and makes no sense.

And also in that case alias is unnecessary.

class C(T)
{
     void foo(T bar) { ... }
}

C!(ref int) baz;

Which still makes no sense.

Is there a reason why you cannot do the following?

class C(T)
{
     void foo(ref T bar) { ... }
}

Because why would you ever want the implementation of a function 
to behave differently depending on whether its parameters are 
passed by reference or not.

In fact instead there should be a ref overload and one without.


More information about the Digitalmars-d mailing list