Library Typedefs are fundamentally broken

Andrej Mitrovic via Digitalmars-d digitalmars-d at puremagic.com
Sun Sep 21 12:57:44 PDT 2014


On 9/21/14, ketmar via Digitalmars-d <digitalmars-d at puremagic.com> wrote:
> On Sun, 21 Sep 2014 08:15:29 -0700
> Andrei Alexandrescu via Digitalmars-d <digitalmars-d at puremagic.com>
> wrote:
>
>> alias Int1 = Typedef!(int, "a.Int1");
>> alias Int2 = Typedef!(int, "b.Int2");
> ah, now that's cool. module system? wut? screw it, we have time-proven
> manual prefixing!

To be fair we now have __MODULE__. Although it does make the call side
a bit ugly. But then again, nothing is stopping anyone from writing a
helper template around Typedef that hides all this ugliness, e.g.:

-----
// helper alias
alias StrongAlias(T, string mod = __MODULE__, size_t line = __LINE__)
    = Typedef!(T, T.init, format("%s.%s.%s", mod, line, T.stringof));

// usage:
alias Int1 = StrongAlias!int;
alias Int2 = StrongAlias!int;
static assert(!is(Int1 == Int2));
-----

This works for me locally. We could add __COLUMN__ to be extra-safe of
course, by then it should be a solved problem.


More information about the Digitalmars-d mailing list