Thread overview
C# Indexers. how to implement them in D.. also property related.
Jun 29, 2010
BLS
Jun 29, 2010
BLS
Jun 29, 2010
Simen kjaeraas
Jun 29, 2010
Trass3r
Jun 29, 2010
BLS
June 29, 2010
Hi, in C# you can do some thing like this.

public interface IDataErrorInfo
{
    // INDEXER	
    string this[string columnName] { get; }
  }
}

how to translate this into D2 ?
thanks in advance, bjoern
June 29, 2010
On Tue, 29 Jun 2010 09:21:34 -0400, BLS <windevguy@hotmail.de> wrote:

> Hi, in C# you can do some thing like this.
>
> public interface IDataErrorInfo
> {
>      // INDEXER	
>      string this[string columnName] { get; }
>    }
> }
>
> how to translate this into D2 ?
> thanks in advance, bjoern

string opIndex(string columnName);
June 29, 2010
On 29/06/2010 15:27, Steven Schveighoffer wrote:
> string opIndex(string columnName);

yeah this is what I did, too..
However defined as ;

interface I1 {
  string opIndex(string columnName);
}

is a no go. So can we say operator overloading within interfaces is not allowed in D2 ?

thanks again Steve.. try to learn the interface/property stuff.
June 29, 2010
BLS <windevguy@hotmail.de> wrote:

> On 29/06/2010 15:27, Steven Schveighoffer wrote:
>> string opIndex(string columnName);
>
> yeah this is what I did, too..
> However defined as ;
>
> interface I1 {
>    string opIndex(string columnName);
> }
>
> is a no go.

Hm. That should have worked.

> So can we say operator overloading within interfaces is not allowed in D2 ?

The new operator overloading scheme has problems with
interfaces. A damned shame if you ask me.

That said, opIndex does not use templates, and should thus
work no problem.


-- 
Simen
June 29, 2010
> interface I1 {
>    string opIndex(string columnName);
> }
>
> is a no go. So can we say operator overloading within interfaces is not allowed in D2 ?

It should work.
Only opBinary etc doesn't work yet cause there are problems with template functions in interfaces.
June 29, 2010
On 29/06/2010 15:35, BLS wrote:
> On 29/06/2010 15:27, Steven Schveighoffer wrote:
>> string opIndex(string columnName);
>
> yeah this is what I did, too..
> However defined as ;
>
> interface I1 {
> string opIndex(string columnName);
> }
>
> is a no go. So can we say operator overloading within interfaces is not
> allowed in D2 ?
>
> thanks again Steve.. try to learn the interface/property stuff.

Jeez, my mistake.. forget to create the implementation. sorry!
June 29, 2010
On Tue, 29 Jun 2010 09:55:50 -0400, BLS <windevguy@hotmail.de> wrote:

> On 29/06/2010 15:35, BLS wrote:
>> On 29/06/2010 15:27, Steven Schveighoffer wrote:
>>> string opIndex(string columnName);
>>
>> yeah this is what I did, too..
>> However defined as ;
>>
>> interface I1 {
>> string opIndex(string columnName);
>> }
>>
>> is a no go. So can we say operator overloading within interfaces is not
>> allowed in D2 ?
>>
>> thanks again Steve.. try to learn the interface/property stuff.
>
> Jeez, my mistake.. forget to create the implementation. sorry!

LOL!   :)

As others have said, templates do not yet work in interfaces, and there is another subtle problem: templates in interfaces are not virtual so they cannot enjoy covariance.  This is a problem for dcollections which uses operators in interfaces.

The only solution right now is to reimplement the template in the derived classes.

Not a fun situation...

-Steve