[Issue 1839] Give D a modern varargs system that allows forwarding
d-bugmail at puremagic.com
d-bugmail at puremagic.com
Fri Feb 15 02:58:07 PST 2008
http://d.puremagic.com/issues/show_bug.cgi?id=1839
------- Comment #10 from wbaxter at gmail.com 2008-02-15 04:58 -------
(In reply to comment #8)
> I misunderstood your initial code sample. In fact that's a simpler problem:
>
> import std.stdio;
>
> void before() {}
> void after() {}
>
> void fn(...)
> {
> foreach (i; 0 .. _arguments.length)
> {
> _arguments[i].print;
> }
> if (_arguments[0] == typeid(int))
> {
> int j = *cast(int *)_argptr;
> writeln(j);
> }
> }
>
> void wrapsFn(T...)(T args)
> {
> before();
> scope(exit) after();
> fn(args);
> }
>
> void main()
> {
> wrapsFn(2, 42, "a");
> }
>
Ok, but it's no longer a function. I can't do with wrapFn the same things I
can do with a regular function, namely taking it's address and passing that
around or calling through it later. If there were a simple and efficient way
to convert the wrapsFn template into a function pointer then I'd be satisfied
with that solution.
--
More information about the Digitalmars-d-bugs
mailing list