variadic args
Aarti_pl
aarti at interia.pl
Mon Dec 11 03:59:45 PST 2006
novice2 napisał(a):
> many thanks, Jarrett Billingsley.
> i don't like templates, so you solution good.
> i hope, Walter will add support for this in language,
> and such ugly construction will gone from sources in future.
You can try with Any ported to D. It allows quite nice solution for
variadic arguments:
void printVector(Any[] vec) {
// printing vector of different type arguments
// see Any description and code; eventually boost any
// documentation
}
void printVariadic(Any[] var...) {
printVector(var);
}
void main() {
Any[] vec;
vec~=(new Any).assign(6);
vec~=(new Any).assign("Text"[]);
vec~=(new Any).assign(5.5);
printVector(vec);
auto v = new Any;
auto z = new Any;
v.assign(2.5);
z.assign("Another text"[]);
printVariadic(v, z);
}
I will send at the end of week updated version of Any, which supports
new opAssign() overloaded operator, so it will be possible:
v=2.5;
instead of
v.assign(2.5);
Using Any you do not have to use va_list, TypeInfo, pointers etc. It's
just redundant then...
I just would wish myself that Walter will add support for templatized
constructors to achieve following:
# printVariadic(new Any(4), new Any("Yet another text"[]), new
Any(3.14)); // it doesn't work now...
Best Regards
Marcin Kuszczak
More information about the Digitalmars-d-learn
mailing list