Pre and Post contracts and signature constraints
simendsjo
simendsjo at gmail.com
Mon Jul 4 10:42:36 PDT 2011
On 04.07.2011 19:20, Zardoz wrote:
> How is the correct way of mix Pre and Post contracts and signature constraints ?
>
> I try this that looks logic way and not compile :
>
> T foo (T) (T a)
> if ( is(T : real)) {
> in {
> assert (a> 0);
> }
> body {
> return a*2;
> }
> }
>
> I get this errors :
> Declaration expected, not 'if'
> unrecognized declaration
>
> And this with same result :
>
> T foo (T) (T a)
> in {
> assert (a> 0);
> }
> if ( is(T : real)) {
> body {
> return a*2;
> }
> }
>
> I'm using dmd 2.053.
>
The "in" should be in a block of it's own:
T foo(T)(T a)
if(...) // notice no { here
in {
} body {
}
More information about the Digitalmars-d-learn
mailing list