[Issue 1839] New: Give D a modern varargs system that allows forwarding
Jarrett Billingsley
kb3ctd2 at yahoo.com
Fri Feb 15 06:15:12 PST 2008
<d-bugmail at puremagic.com> wrote in message
news:bug-1839-3 at http.d.puremagic.com/issues/...
> http://d.puremagic.com/issues/show_bug.cgi?id=1839
>
> Summary: Give D a modern varargs system that allows forwarding
> Product: D
> Version: 2.010
> Platform: PC
> OS/Version: Windows
> Status: NEW
> Severity: enhancement
> Priority: P2
> Component: DMD
> AssignedTo: bugzilla at digitalmars.com
> ReportedBy: wbaxter at gmail.com
>
>
> Given function
>
> void A(...) {
> ...
> }
>
> It should be possible to write a function wrapsA of this sort:
>
> void wrapsA(...) {
> pre_call();
> A(...); // or whatever syntax you want for forwarding the varargs.
> post_call();
> }
>
> That D -- a supposedly modern, easy-to-use languages -- can't do this
> conceptually simple thing is sad.
>
> The whole point of procedural programming is that code is encapsulated
> into
> reusable blocks. Not being able to forward varargs means that a big chunk
> of
> that reusability is lost any time you write a varargs function.
>
> The workaround is to write every varargs function in two flavors, one
> thats got
> (...) args, and one that's got (_argptr,_arguments) args. But if the
> solution
> is so mechanical and straightforward then why can't the compiler at just
> do
> that for us? I'm not saying that's the right way to implement vararg
> forwarding, but barring a more elegant solution, that sounds like at least
> a
> plausible solution.
I'll suggest it again: given a typesafe variadic function whose variadic
parameter's array element type is a struct:
void A(Variant[] args...)
calling that function:
A(1, 2, "hi")
should be sugar for:
A(Variant(1), Variant(2), Variant("hi"))
This alone would obviate the need for ... style vararg functions. A Variant
array is far, far more useful than the platform-dependent hard-to-use
inflexible _arguments/_argptr crap. And at the same time, solves the "OMG
template bloat!!" problem.
More information about the Digitalmars-d-bugs
mailing list