www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Re: Library Typedefs are fundamentally broken (alternate

reply Andrej Mitrovic via Digitalmars-d <digitalmars-d puremagic.com> writes:
Guys, all this fighting around. Can't we do something like the
following and sort this out?

-----
import std.string;
import std.typecons;

private struct RealTypedef(T, T init_val, string cookie)
{
    /// implementation here...
}

template Typedef(T, T init_val = T.init,
    string cookie = "", string mod = __MODULE__, size_t line = __LINE__)
{
    static if (cookie == "")
        enum the_cookie = format("%s_%s_%s", mod, line, T.stringof);
    else
        alias the_cookie = cookie;

    alias Typedef = .RealTypedef!(T, init_val, the_cookie);
}

alias Type_1 = Typedef!(void*);
alias Type_2 = Typedef!(void*);
static assert(!is(Type_1 == Type_2));  /// safe by default (different types)

alias Same_Type_1 = Typedef!(void*, null, "cookie");
alias Same_Type_2 = Typedef!(void*, null, "cookie");
static assert(is(Same_Type_1 == Same_Type_2));   // unsafe *only if
you request it*

void main ( )
{
}
-----
Sep 23 2014
next sibling parent "bearophile" <bearophileHUGS lycos.com> writes:
Andrej Mitrovic:

 alias Same_Type_1 = Typedef!(void*, null, "cookie");
 alias Same_Type_2 = Typedef!(void*, null, "cookie");
 static assert(is(Same_Type_1 == Same_Type_2));   // unsafe 
 *only if you request it*
I suggest to not offer this usage possibility. Bye, bearophile
Sep 23 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Tuesday, 23 September 2014 at 14:59:37 UTC, Andrej Mitrovic 
via Digitalmars-d wrote:
 Guys, all this fighting around. Can't we do something like the
 following and sort this out?

 -----
 import std.string;
 import std.typecons;

 private struct RealTypedef(T, T init_val, string cookie)
 {
     /// implementation here...
 }

 template Typedef(T, T init_val = T.init,
     string cookie = "", string mod = __MODULE__, size_t line = 
 __LINE__)
 {
     static if (cookie == "")
         enum the_cookie = format("%s_%s_%s", mod, line, 
 T.stringof);
     else
         alias the_cookie = cookie;

     alias Typedef = .RealTypedef!(T, init_val, the_cookie);
 }

 alias Type_1 = Typedef!(void*);
 alias Type_2 = Typedef!(void*);
 static assert(!is(Type_1 == Type_2));  /// safe by default 
 (different types)

 alias Same_Type_1 = Typedef!(void*, null, "cookie");
 alias Same_Type_2 = Typedef!(void*, null, "cookie");
 static assert(is(Same_Type_1 == Same_Type_2));   // unsafe 
 *only if
 you request it*

 void main ( )
 {
 }
 -----
Andrei objects it.
Sep 23 2014
parent reply Andrej Mitrovic via Digitalmars-d <digitalmars-d puremagic.com> writes:
On 9/23/14, Dicebot via Digitalmars-d <digitalmars-d puremagic.com> wrote:
 Andrei objects it.
Well I was hoping to get a compromise between the community and the (benevolent) dictator this way. :)
Sep 23 2014
parent Andrei Alexandrescu <SeeWebsiteForEmail erdani.org> writes:
On 9/23/14, 12:52 PM, Andrej Mitrovic via Digitalmars-d wrote:
 On 9/23/14, Dicebot via Digitalmars-d <digitalmars-d puremagic.com> wrote:
 Andrei objects it.
Well I was hoping to get a compromise between the community and the (benevolent) dictator this way. :)
I'm as happy as the next guy with changes that move things forward and handle backwards compatibility graciously. -- Andrei
Sep 23 2014