Re: query interface

2009-01-21 Thread BCS
Reply to Qian, Frits van Bommel wrote: Qian Xu wrote: Hi All, can D check, whether a class A an Interface B supports? like: if (supports(class_A, intf_B)) if (is(class_A : intf_B)) tests if 'class_A' is implicitly convertible to 'intf_B'. If the first is a class and the second an interf

Re: query interface

2009-01-21 Thread Trass3r
Qian Xu schrieb: Thanks. Could you tell me, how to make a function for this? I do not know how to pass an Interface as parameter. like bool supports(T)(T obj, interface_type t) { return (is(obj : t)); } Guess something like bool supports(T, I) (T obj) { return (is(obj : I));

Re: query interface

2009-01-21 Thread Qian Xu
Frits van Bommel wrote: > Qian Xu wrote: >> Hi All, >> >> can D check, whether a class A an Interface B supports? >> >> like: >> >> if (supports(class_A, intf_B)) > > if (is(class_A : intf_B)) > tests if 'class_A' is implicitly convertible to 'intf_B'. If the first > is a class and the

Re: query interface

2009-01-21 Thread Jarrett Billingsley
On Wed, Jan 21, 2009 at 10:30 AM, Qian Xu wrote: > Hi All, > > can D check, whether a class A an Interface B supports? > > like: > > if (supports(class_A, intf_B)) > { > cast(intf_B) (class_A).hello(); > } At compile time, like Frits said, you can use is(class_A : intf_B). At runtime, you

Re: query interface

2009-01-21 Thread Frits van Bommel
Qian Xu wrote: Hi All, can D check, whether a class A an Interface B supports? like: if (supports(class_A, intf_B)) if (is(class_A : intf_B)) tests if 'class_A' is implicitly convertible to 'intf_B'. If the first is a class and the second an interface, that's equivalent to the class

Re: query interface

2009-01-21 Thread Qian Xu
Qian Xu wrote: > Hi All, > > can D check, whether a class A an Interface B supports? > > like: > > if (supports(class_A, intf_B)) > { > cast(intf_B) (class_A).hello(); > } > > --Qian what I have found is: if (is(class_A == intf_B)) { cast(intf_B) (class_A).hello(); } Is

query interface

2009-01-21 Thread Qian Xu
Hi All, can D check, whether a class A an Interface B supports? like: if (supports(class_A, intf_B)) { cast(intf_B) (class_A).hello(); } --Qian