Idea: extend typesafe variadic functions

Jarrett Billingsley kb3ctd2 at yahoo.com
Sun Apr 1 08:41:44 PDT 2007


"Daniel Keep" <daniel.keep.lists at gmail.com> wrote in message 
news:eundlt$sl7$1 at digitalmars.com...
> I'm afraid I can't :(
>
> I imagine that there's probably some very nice things you could do with
> this, but I can't see why you couldn't do it already:
>
> void funcT(Ts...)(Ts args)
> {
>    A[] as;
>    as.length = args.length;
>    foreach( i, arg ; args )
>        as[i] = new A(arg);
>
>    func(as);
> }

You got it!  See, if we could do this, this would allow these kind of 
functions to be non-templated, meaning far less code bloat, the ability to 
overload, and the ability to override in classes, but with almost the same 
amount of expressiveness.  People writing scripting language binding 
libraries might find it _very_ useful..

> Getting this to work with overloads would be... interesting, but
> certainly doable.  Heck, you could probably turn the above into a
> generic templated "array-of-T" initializer.

I was thinking about that.  But then you've still got the code bloat 
issues..

> On a side note, am I the only one who is *really* uncomfortable with the
> fact that the first example works at all?  :S

I think it's pretty cool, though I can see why you're kind of wary of it. 
Most of the rest of the language doesn't use implicit conversions. 





More information about the Digitalmars-d mailing list