Andrei Alexandrescu wrote:
Tomas Lindquist Olsen wrote:
On Fri, Apr 3, 2009 at 5:20 PM, Andrei Alexandrescu
<[email protected]> wrote:
Jarrett Billingsley wrote:
On Fri, Apr 3, 2009 at 10:38 AM, Eljay <[email protected]> wrote:
Alas, I'm not sure how to pass the variadic arguments through to
another
variadic function, with this
signature:
void perform(...)
You can't. D's varargs suck.
Of course you can. Where did that come from?
void foo(T...)(T args) { bar(args); }
void bar(T...)(T args) { foreach (a; args) writeln(a); }
void main()
{
foo(3, 4.5);
}
prints:
3
4.5
Andrei
That's not a D vararg, it's a variadic template!
Well I guess I'll take that as a compliment.
I've made proposals to allow this properly (without templates) before
so I'm not going to waste time on that again...
I, too, believe it would be a waste of time, but probably for different
reasons. Look at this:
void fun(...)
{
... use void* _argptr and TypeInfo[] _arguments ...
}
I'll ignore the fact that binding the arguments to magic, predefined
names has the elegance of a fart interrupting a solemn moment. The
larger problem is the type of _argptr.
That surprises me. Your string mixin callbacks (or whatever is the
correct name for this idiom) in std.algorithm also use magic, predefined
names like "a".
No safety can be built into a function that traffics in void*, EVER. No
matter what you do. A proverb goes "No matter how nicely you dress a
mule, you'll still call it a mule." (It was s/mule/ass/g in Romanian,
but ass is ambiguous in English.) So yes, it would be a waste of time to
embellish a fundamentally deeply unsafe feature. A better use of time
would be to improve its safe counterpart.
The void* is paired with a TypeInfo. A Variant uses raw data and
TypeInfo, and manages to be reasonably safe. If you want guaranteed
safety, you must use something like Java (or SafeD vaporware).
Andrei