__traits so long and ugly, what about ::?

KennyTM~ kennytm at gmail.com
Wed Mar 30 12:45:30 PDT 2011


On Mar 31, 11 03:28, Ary Manzana wrote:
> I think :: is not used in the language.
>
> In a recent article about D I saw:
>
> mixin(__traits(identifier, T) ~ " " ~
> to!string(tolower(__traits(identifier, T)[0])) ~
> __traits(identifier, T)[1..$] ~ ";");
>
> What if foo::bar were an alias for __traits(foo, bar) ?
>
> The code would look like this:
>
> mixin(T::identifier ~ " " ~
> to!string(tolower(T::identifier[0])) ~
> T::identifier[1..$] ~ ";");
>
> What do you think?
>
> Another uses:
>
> __traits(int, isArithmetic) ==> int::isArithmetic
> __traits(C, isAbstractClass) ==> C::isAbstractClass
>

You've got the order wrong.

> __traits(hasMember, S, "m") ==> S::hasMember("m")
>
> Well, you get the idea...
>
> :: might be applied to other compile time uses, but I just came up with
> this...

-1.

This is confusing as :: is used to separate scopes in C++ (and PHP too). 
e.g.

     struct A {
        int x;
        bool isSame(const A other) pure const { return x == other.x; }
     }

     void main () {
        A a = A(2), b = A(2);
        assert (  a.isSame(b));   // ok
        assert (! a::isSame(b));  // ???
     }

(How about that 'meta' namespace proposal? meta.hasMember(S, "m") )



More information about the Digitalmars-d mailing list