digitalmars.D - mixin code
- Ivan Senji (69/69) Jun 24 2004 I was trying to mixin a class from another file without having to
- Walter (4/11) Jun 24 2004 not?
- Ivan Senji (4/18) Jun 25 2004 That's ok, it isn't that important to me now, i only asked because i tho...
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
"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 ornot? No, sorry.
Jun 24 2004
"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...That's ok, it isn't that important to me now, i only asked because i thought i read something about something like that.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 ornot? No, sorry.
Jun 25 2004








"Ivan Senji" <ivan.senji public.srce.hr>