October 10, 2013 Template constraint error. | ||||
---|---|---|---|---|
| ||||
Using Debian7, gcc-4.8, gdc-4.8 from the `testing main` debian source. import std.stdio; class Bar(T) if (is(T == int)) { this() { writefln(T.stringof); } } class Foo(T) : Bar!(int) if (is(T == string)) // <-- template constraint causes error. { this() { super(); writefln(T.stringof); } } void main() { auto baz = new Foo!(string)(); } $ gdc test.d -o test test.d:11: Error: members expected test.d:11: Error: { } expected following aggregate declaration test.d:11: Error: Declaration expected, not 'if' test.d:16: Error: function declaration without return type. (Note that constructors are always named 'this') test.d:16: Error: no identifier for declarator writefln(T.stringof) test.d:17: Error: unrecognized declaration |
October 10, 2013 Re: Template constraint error. | ||||
---|---|---|---|---|
| ||||
Posted in reply to Gary Willoughby | Am Thu, 10 Oct 2013 16:46:18 +0200
schrieb "Gary Willoughby" <dev@nomad.so>:
> class Foo(T) : Bar!(int) if (is(T == string)) // <--
> template constraint causes error.
This syntax was added in a more recent frontend release. You should do this instead for older frontend versions:
-------
class Foo(T) if (is(T == string)) : Bar!(int)
-------
|
Copyright © 1999-2021 by the D Language Foundation