www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - mixin code

reply "Ivan Senji" <ivan.senji public.srce.hr> writes:
I was trying to mixin a class from another file without having to
insert it to the compile line, so this is what i did:


//file args.d
//this is what i would like to mixin
////////////////////////////////////////////
module args;

template args()
{

    class Arguments
    {
         this(TypeInfo[] inf, void* argptr)
         {
              typeinfos = inf;
              pointers.length = inf.length;
              pointers[0] = argptr;
              for(int i=1; i<inf.length; i++)
              {
                   pointers[i] = pointers[i-1] + inf[i-1].tsize;
              }
         }
         int length(){return typeinfos.length;}
         TypeInfo type(int i){return typeinfos[i];}
         void* value(int i){return pointers[i];}
         private
         {
              TypeInfo[] typeinfos;
              void*[] pointers;
         }
    }
}
/////////////////////////////////////////////////

//the file where it is mixed to:
//testvarargs.d
////////////////////////////////////////////
import std.stream;

import args;
mixin args.args!();

void func(...)
{
     Arguments arg = new Arguments(_arguments,_argptr);
     stdout.printf("Funkcija func pozvana s %d argumenata",arg.length);
     for(int i=0; i<arg.length; i++)
     {
          if(arg.type(i) == typeid(float))
          {
           //stdout.printf("%d
          }
     }
}

int main ( char [] [] args )
{
 func(100,3.141);
 getch();
 return 1;
}
//////////////////////////////////////////

This works (even though i had some unreproducable linking errors)
but it gets more complicated if in args.d the template is called the same as
class,
and i have a feeling something like template modules was mentioned in this
NG
some time ago, but does it still exist? Is it documented anywhere?

I think it went something like:
//a.d
module a(T);

//b.d
import a!(int);

?

This would be a good way to import templated code, but does it exist or not?
Jun 24 2004
parent reply "Walter" <newshound digitalmars.com> writes:
"Ivan Senji" <ivan.senji public.srce.hr> wrote in message
news:cbe19f$8cm$1 digitaldaemon.com...
 I think it went something like:
 //a.d
 module a(T);

 //b.d
 import a!(int);

 ?

 This would be a good way to import templated code, but does it exist or
not? No, sorry.
Jun 24 2004
parent "Ivan Senji" <ivan.senji public.srce.hr> writes:
"Walter" <newshound digitalmars.com> wrote in message
news:cbfdjv$2ac3$1 digitaldaemon.com...
 "Ivan Senji" <ivan.senji public.srce.hr> wrote in message
 news:cbe19f$8cm$1 digitaldaemon.com...
 I think it went something like:
 //a.d
 module a(T);

 //b.d
 import a!(int);

 ?

 This would be a good way to import templated code, but does it exist or
not? No, sorry.
That's ok, it isn't that important to me now, i only asked because i thought i read something about something like that.
Jun 25 2004