www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - New template problem

reply bearophile <bearophileHUGS lycos.com> writes:
After a painful search I have found a new bug in my libs, that comes out using
DMD 1.030 (with 1.029 the following code works):

template HasLength(T) {
    // const bool HasLength = is(typeof(T.length)) || is(typeof(T.init.length));
    const bool HasLength = is(typeof(T.length));
}

void main() {
    class Foo { int length; }
    //assert(!HasLength!(typeof( new Foo )));
    assert(!HasLength!(typeof( new Foo )));
}

Output (DMD 1.030):
Error: this for length needs to be type Foo not type int

Do you have some workaround/suggestion?
Bye,
bearophile
May 18 2008
parent reply "Steven Schveighoffer" <schveiguy yahoo.com> writes:
"bearophile"  wrote
 After a painful search I have found a new bug in my libs, that comes out 
 using DMD 1.030 (with 1.029 the following code works):

 template HasLength(T) {
    // const bool HasLength = is(typeof(T.length)) || 
 is(typeof(T.init.length));
    const bool HasLength = is(typeof(T.length));
 }

 void main() {
    class Foo { int length; }
    //assert(!HasLength!(typeof( new Foo )));
    assert(!HasLength!(typeof( new Foo )));
 }

 Output (DMD 1.030):
 Error: this for length needs to be type Foo not type int

 Do you have some workaround/suggestion?

Any reason why you use HasLength!(typeof(new Foo)) vs HasLength!(Foo)? -Steve
May 19 2008
parent bearophile <bearophileHUGS lycos.com> writes:
Steven Schveighoffer:
 Any reason why you use HasLength!(typeof(new Foo)) vs HasLength!(Foo)?

Nope. (I have reverted to DMD 1.029 because 1.030 doesn't work for me, so I can't tell you if your version too produces the bug). Bye and thank you, bearophile
May 19 2008