Interface problems

Steven Schveighoffer schveiguy at yahoo.com
Wed Jan 26 05:54:08 PST 2011


On Wed, 26 Jan 2011 05:12:39 -0500, Dmitry Olshansky  
<dmitry.olsh at gmail.com> wrote:

> On 26.01.2011 8:12, Mandeep Singh Brar wrote:
>> Mandeep Singh Brar:
>>
>>> I am not able to:
>>>
>>> - find indexOf interface in an interface range using std.algorithm.
>>> I don't understand. Please explain better.
>> In the following snippet:
>>       Interface interfaceA{}
>>       class C:interfaceA{}
>>       class D:interfaceA{}
>>
>>       interfaceA[] registry;
>>       register(interfaceA a) { registry ~= a; }
>>       unregister(interfaceA a) {idx = registry.indexOf(a);  
>> registry.replace(idx,
>> idx+1, null); }
>> In the above statement indexOf does not work.
>>
>
> You should use 'is' for such kind of thing. The problem is that == uses  
> opEquals or opCmp, there is no such thing for interfaces AFIKT. But for  
> every pointer like type we can check if they are the same with 'is'.

This is hardly a solution.  He wants to do value comparison, not identity  
comparison.

The real fix is to make interface assume it is an Object, so it can be  
implicitly cast to Object, and find another way to implement COM  
interfaces.  The COM interface "hack" is way outdated and extremely  
harmful, esp. on OS' who *don't use COM*!  I can't see how the benefits it  
has outweigh the problems it causes.

-Steve


More information about the Digitalmars-d-learn mailing list