www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Implicit Template Properties and Mixins

reply Vathix <vathix dprogramming.com> writes:
As stated in template.html, "If a template has exactly one member in it,  
and the name of that member is the same as the template name, that member  
is assumed to be referred to in a template instantiation", could this be  
expanded to also apply to a mixin's MixinIdentifier? Such as:


template MixFoo(T, T VALUE = T.init)
{
    T MixFoo = VALUE;
}

int main()
{
    mixin MixFoo!(int, 3) mfoo;
    printf("%d\n", mfoo); // Instead of mfoo.MixFoo. Prints 3.
    return 0;
}


So that mfoo is treated as type T (int) instead of a mixin, since MixFoo  
is the only member in the template and has the same name. I think this  
will add much eloquence.
Jun 12 2005
parent "Maxime Larose" <mlarose broadsoft.com> writes:
I also tried that before. FWIW, I agree with you, it would add much
eloquence and allow a certain (very) restricted form of macros to D.



"Vathix" <vathix dprogramming.com> wrote in message
news:op.sr9p27m0kcck4r esi...
 As stated in template.html, "If a template has exactly one member in it,
 and the name of that member is the same as the template name, that member
 is assumed to be referred to in a template instantiation", could this be
 expanded to also apply to a mixin's MixinIdentifier? Such as:


 template MixFoo(T, T VALUE = T.init)
 {
     T MixFoo = VALUE;
 }

 int main()
 {
     mixin MixFoo!(int, 3) mfoo;
     printf("%d\n", mfoo); // Instead of mfoo.MixFoo. Prints 3.
     return 0;
 }


 So that mfoo is treated as type T (int) instead of a mixin, since MixFoo
 is the only member in the template and has the same name. I think this
 will add much eloquence.

Jun 13 2005