March 27, 2007
> 
> How about:
> 
.....
> 
> That should already work.
> 
> Cheers,
> 
> Reiner

I put into my compiler:

interface Storage {
    Storage param1(int);
}

abstract class StorageImpl(T) : Storage {
    static assert(is(typeof(this) == T));

        T param1(int p1)
        {
                this.p1 = p1;
                return cast(T)this;
        }
        private int p1;
}

class SpecificStorage : StorageImpl!(SpecificStorage) {
        SpecificStorage param2(bool p2) {
                this.p2 = p2;
                return this;
        }
        private bool p2;
}

void main() {
        auto c = (new SpecificStorage).param1(4).param2(true);

        writefln(SpecificStorage.p1, " --- ", SpecificStorage.p2);

}


... and get errors using DMD 1.009 on Linux:
covariance.d(5): class covariance.StorageImpl!(SpecificStorage).StorageImpl
unable to resolve forward reference in definition
covariance.d(16): class covariance.SpecificStorage unable to resolve forward
reference in definition

Errors on declaration of "class StorageImpl(T)" and "class SpecificStorage".

To say true I don't know why they appear - IMHO it should compile. Maybe it's bug?


-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
March 27, 2007
Reiner Pope wrote:
> 
> How about:
> 
> interface Storage
> {
>      Storage param1(int);
> }
> 
> abstract class StorageImpl(T) : Storage {
>      static assert(is(typeof(this) == T));
> 
>      T param1(int p1)
>      {
>          this.p1 = p1;
>          return cast(T)this;
>      }
>      private int p1;
> }
> 
> class SpecificStorage : StorageImpl!(SpecificStorage) {
>      SpecificStorage param2(bool p2) {
>          this.p2 = p2;
>          return this;
>      }
>      private bool p2;
> }
> 
> That should already work.
> 
> Cheers,
> 
> Reiner

I get problems with compiling this (I put info in another post). But even if it would work I think that problem should be just fixed not only worked around. For my own "hot-fix" workaround I used template mixin.

The problem is that solution is just complicated for simple use. It's *unnecessary* complicated as it can be solved by fixed current clumsy covariant feature.

Best what could be worked out up till now is in: http://www.digitalmars.com/webnews/newsgroups.php?art_group=digitalmars.D&article_id=51241

(It's my before previous post.)

-- 
Regards
Marcin Kuszczak (Aarti_pl)
-------------------------------------
Ask me why I believe in Jesus - http://zapytaj.dlajezusa.pl (en/pl)
Doost (port of few Boost libraries) - http://www.dsource.org/projects/doost/
-------------------------------------
1 2
Next ›   Last »