Objective-D, reflective programming, dynamic typing
Andrei Alexandrescu
SeeWebsiteForEmail at erdani.org
Sat Apr 4 11:13:40 PDT 2009
grauzone wrote:
> Andrei Alexandrescu wrote:
>> Georg Wrede wrote:
>>> Andrei Alexandrescu wrote:
>>>>
>>>> void foo_templated(T...)(T args)
>>>> {
>>>> Variant[args.length] dynatyped;
>>>> foreach (i, arg; args) dynatyped[i] = arg;
>>>> return foo(dynatyped);
>>>> }
>>>> void foo(Variant[] dynatyped...)
>>>> {
>>>> ...
>>>> }
>>>
>>> Hmm. An idiom. My sweet tooth just got thirsty for syntactic sugar!
>>
>> When opImplicitCastFrom will be implemented, foo's definition will be
>> enough. You'll write foo(1, 2.3, "a") and the compiler will rewrite it
>> to foo(Variant(1), Variant(2.3), Variant("a")).
>
> This looks very good. How exactly will it work?
Variant will implement opImplicitCastFrom(T) for all types T. The "..."
in foo's declaration already allows variadic arguments. The rest will be
taken care of by the compiler.
So IMHO:
(a) Variadics with templates are good;
(b) Variadics with uniform-type arrays are good;
(c) We should avoid variadics with void*.
Andrei
More information about the Digitalmars-d
mailing list