lurker napisał: >> class C >> { >>int draw(){ return 10; } >> } >> interface Drawable >> { >>long draw(); >> } >> ... >> auto c = new C; >> auto d = duck!Drawable(c); > > Object c = new C; > auto d = duck!Drawable(c); // awes > > does this work? After all, c is a C:
I'd say no. c is an Object, you don't know it can draw(). > Object c = new C; > auto d = duck!Drawable(cast(C)c); Yeah, that's what you have to do. > One fears this feature has little real world use. But it's a great way to > add additional bloat to the puny little Phobos... > > It's amusing as always that the syntax is being discussed before we even > know how this works. How does the int -> long coercion work there? Any > possibility to get a written spec for this? I got a similar feeling after seeing there's 70+ posts in this thread. There's not even a link to the source to know what one is naming. For one thing, I'd like to know whether (Duck|As|AdaptTo)!I is a class implementing I or a struct mimicking I's API. Or if in duck!I(a) a already implements I, does Duck alias itself away? Or if in duck!I(a) a is a struct exposing I's methods (walks and quacks like I), does Duck alias itself away? What if I has an alias this to one of its properties? What if I has static methods? -- Tomek