Combining Delegate and Functions

Jarrett Billingsley jarrett.billingsley at gmail.com
Fri Jul 3 21:49:54 PDT 2009


On Fri, Jul 3, 2009 at 3:36 PM, Eric Poggel<dnewsgroup at yage3d.net> wrote:
>
> I use variadic template args also, but templates are often confusing to new
> users, hence my suggestion.

I don't really buy that argument, only because if you're going to use
D without templates?  you might as well use Java pre-generics.
Really.  Generic programming is what makes D _D_.

> Also, if you want to do something like what I
> habe below, I believe you have to resort to darker tuple magic.
>
> void foo(int a, ...)
> {       bar(foo.arguments); // also passes a
> }
> void bar(...)
> {
> }

void foo(T...)(int a, T args) { bar(a, args); }
void bar(T...)(T args) {}

Also, forwarding varargs with normal ...-style variadic functions is
currently - unexcusably - impossible.

> Also, do you see any problems that would arise from replacing functions with
> delegates internally, so that no more conversions between them would be
> required?

I would see no problem in allowing an implicit conversion from
function pointer to delegate.  All the compiler would do is insert a
thunk.  Then APIs would just always take delegates, and "raw" function
pointers would still be useful for cases where a delegate is
undesirable (i.e. when being passed to a library that the GC doesn't
scan, and for compatibility with the C ABI).



More information about the Digitalmars-d mailing list