dynamic classes and duck typing

retard re at tard.com.invalid
Tue Dec 1 07:25:47 PST 2009


Tue, 01 Dec 2009 15:14:56 +0200, Max Samukha wrote:

> On Tue, 1 Dec 2009 11:45:14 +0000 (UTC), retard <re at tard.com.invalid>
>>Agreed. But this new feature is a bit confusing - there isn't anything
>>dynamic in it. It's more or less a compile time rewrite rule. It becomes
>>dynamic when all of that can be done on runtime and there are no
>>templates involved.
> 
> But the feature can be used to implement fully dynamic behavior
> (provided there is extended RTTI, which is already implementable on top
> of compiletime introspection using a tweaked compiler). For example,
> Variant can implement opDispatch to forward calls to the contained
> object:
> 
> void foo(Variant o) {
> 	o.duckMethod();
> }
> 
> foo(Variant(new class { void duckMethod() {} }));
> 
> BTW, it is not possible currently to create a Variant from a void
> pointer to the object and the meta-object of that object because D's
> meta-objects are lacking necessary information. But that is fixable, I
> guess.

Ok, good to know.



More information about the Digitalmars-d mailing list