On Tuesday, 11 December 2012 at 07:15:38 UTC, Zhenya wrote:
I'm sorry for my english.
I know that D != Python and my example don't need
any RTTI.

D has alias this feature.My example shows that we can use alias this with types.
And I just want use this:

struct Type(T)
{
   alias T m_type;
   alias m_type this;
}

int main()
{
   Type!int Int;
   Int i;//should compile by definition of alias this
}

My I ask, why not just use int directly?

I'm not proficient enough with D yet but it seems to me that the example does not make sense.

alias T m_type;
alias m_type this;

should be equivalent to

alias T this;

which, in some sense makes struct Type(T) equal to T... which is what you are thinking, I think.

But! I also believe that structs are meant as value types and are addressable.

So when you do

Int i; you are essentially doing something like

int x;
x i;

which makes no sense.

If you do this instead,

        alias Type!int Int;
        Int i;

then it will compile, of course.

But your way, when you do Int x; you are specifically trying to create a instance of an object. Yet you are not wanting it to be an object and I'm not sure what you are wanting x to be. (another type? a type of a type?)



Reply via email to