Reimplementing the bulk of std.meta iteratively

Walter Bright newshound2 at digitalmars.com
Fri Oct 2 04:04:53 UTC 2020


On 10/1/2020 5:41 AM, Timon Gehr wrote:
> On 01.10.20 10:59, Walter Bright wrote:
>> On 10/1/2020 12:51 AM, Timon Gehr wrote:
>>> Maybe this is related to what you mean?
>>>
>>> type t = readln().strip()=="int"?int:double;
>>> auto f = (t x)=>x;
>>
>>
>> As D is a statically typed language, I don't see how that can ever work.
> 
> The example is easy to type check statically. In terms of ABI, you just have to 
> make sure that `f` can find the context pointer without already knowing the 
> value of `t`, then it can reconstruct everything it needs to know.

I think you described D's "class" type. To make it work with int and double, 
you'd need to "box" them with a class. Like Java.


More information about the Digitalmars-d mailing list