Library Typedefs are fundamentally broken

Dicebot via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 07:22:54 PDT 2014


On Saturday, 20 September 2014 at 17:20:28 UTC, Andrei 
Alexandrescu wrote:
> On 9/20/14, 9:32 AM, ketmar via Digitalmars-d wrote:
>> On Sat, 20 Sep 2014 08:25:17 -0700
>> Andrei Alexandrescu via Digitalmars-d 
>> <digitalmars-d at puremagic.com>
>> wrote:
>>
>>> I think this is an entirely palatable idiom:
>>> alias ALfloat = std.typecons.Typedef!(float, "ALfloat");
>> this is ugly.
>
> But not unusable.

Requiring manual tracing of identity = unusable. With my proposed 
implementation it is at least clear when it is going to fail. 
This is much worse:

module a;

alias Int1 = Typedef!(int, "MyInt");

module b;

alias Int2 = Typedef!(int, "MyInt");

// oh I didn't know someone else used that cookie too..
static assert (is(Int1 == Int2));

Such solution simply can't be allowed in any project with >1 
active programmer unless either type safety is not important or 
some additional restrictions on adding new typedefs are added 
process-wise (insane).


More information about the Digitalmars-d mailing list