refInt = ref int: how to achieve this? or is this a bug?

mw mingwu at gmail.com
Wed Jun 17 21:08:26 UTC 2020


On Wednesday, 17 June 2020 at 20:47:59 UTC, Steven Schveighoffer 
wrote:
> On 6/17/20 4:38 PM, mw wrote:
> It's not possible in this way. ref is a storage class and not 
> part of the type.
>
> Essentially, your alias statement becomes:
>
> alias refInt = int;
>
> Which in itself is somewhat of a "feature", as storage classes 
> that do not apply are ignored. Some may consider it a bug, but 
> I haven't seen anyone attempt something like what you have, it 
> sure seems like the compiler should complain.

I'm trying to typedef a PushT here:

https://github.com/mingwugmail/liblfdsd/blob/master/liblfds.dpp#L52

The C interface only accept void*, so I need different PushT type 
for different D type (basic type int|double, ..., struct, class, 
stirng|array).

Without be able to `alias PushT = ref T`, it's hard to define 
this func:

https://github.com/mingwugmail/liblfdsd/blob/master/liblfds.dpp#L72

bool push(PushT value) {
   ...
}

Any work-around? or suggestions how to structure the D code?



More information about the Digitalmars-d mailing list