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

mw mingwu at gmail.com
Thu Jun 18 00:19:01 UTC 2020


On Wednesday, 17 June 2020 at 23:58:37 UTC, mw wrote:
> On Wednesday, 17 June 2020 at 23:48:52 UTC, Stanislav Blinov 
> wrote:
>>> f(    T) /*more static if here*/ { /*potential dup code 
>>> here*/ }
>>> f(ref T) /*more static if here*/ { /*potential dup code 
>>> here*/ }
>>>
>>> I would call for improvement.
>>
>> Again, looking at your code, this all comes out of your trying 
>> to conflate references and pass by reference. References (i.e. 
>> classes) and values (i.e. primitive types and structs) are 
>> semantically different, so should be treated differently.
>
> It has to be done: because the C lib only accept void* as value.
>
> So on the D side, need to pass to C:
>
> -- primitive types, class (essentially pointers) by value
> -- struct, union, array|string, by reference
>
> The discussion here is how to make this passing code simple to 
> write.


OK, guess Auto Ref Parameters is specially designed for this:

https://dlang.org/spec/template.html#auto-ref-parameters





More information about the Digitalmars-d mailing list