www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Request with mixins

reply J Anderson <REMOVEanderson badmama.com.au> writes:
I would like to be able to do something like this:

template A(T) { }


class C
{
    mixin A!(typeof(this));
}

or parhaps:

template A(T) { }

class C
{
    mixin A!(this);
}

Which would be the same as:

template A(T) { }

class C
{
    mixin A!(C);
}


It's just about making code more generic.

It could also be used within mixins, so you would have no need to pass 
the class name by parameter:

template C()
{
     typeof(this) getType() {..}
}

-- 
-Anderson: http://badmama.com.au/~anderson/
May 22 2004
next sibling parent J Anderson <REMOVEanderson badmama.com.au> writes:
Of course "this" doesn't exist for static object, however the static 
type name could be called something else like "me".

J Anderson wrote:

 I would like to be able to do something like this:

 template A(T) { }


 class C
 {
    mixin A!(typeof(this));
 }

 or parhaps:

 template A(T) { }

 class C
 {
    mixin A!(this);
 }

 Which would be the same as:

 template A(T) { }

 class C
 {
    mixin A!(C);
 }


 It's just about making code more generic.

 It could also be used within mixins, so you would have no need to pass 
 the class name by parameter:

 template C()
 {
     typeof(this) getType() {..}
 }

-- -Anderson: http://badmama.com.au/~anderson/
May 22 2004
prev sibling parent Norbert Nemec <Norbert.Nemec gmx.de> writes:
I fully second that proposal.

Even though "this" only exists within non-static functions, "typeof(this)"
should definitely be allowed in the whole class.

B.t.w: This is again an idea from Sather. D-mixins are similar to inclusion
of classes, so a special type "SAME" is defined, which is always replaced
by the type of the including class. This would even allow stuff like:

-------------------------------
template LinkedList {
        typeof(this) next;
}

class Node {
        mixin LinkedList;
}
-------------------------------



J Anderson wrote:

 
 I would like to be able to do something like this:
 
 template A(T) { }
 
 
 class C
 {
     mixin A!(typeof(this));
 }
 
 or parhaps:
 
 template A(T) { }
 
 class C
 {
     mixin A!(this);
 }
 
 Which would be the same as:
 
 template A(T) { }
 
 class C
 {
     mixin A!(C);
 }
 
 
 It's just about making code more generic.
 
 It could also be used within mixins, so you would have no need to pass
 the class name by parameter:
 
 template C()
 {
      typeof(this) getType() {..}
 }
 

May 23 2004