Are contracts intended for verifying @safety;
Somebody via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Nov 7 12:16:49 PST 2016
On Monday, 7 November 2016 at 19:30:01 UTC, ag0aep6g wrote:
> No, it's not ok. Contracts and (most) asserts are not included
> in release builds, but the rules for @safe/@trusted don't
> change. So you'd be breaking @safe in release builds.
>
> You can use std.exception.enforce instead, in the body instead
> of a contract:
>
> void moveFrom(int[] a, in int[] b) @trusted
> {
> import std.exception: enforce;
> enforce(a.length >= b.length);
> memmove(/* ... as above ... */);
> }
Can the version switch be used to detect noboundscheck? I was
thinking that if, it could be used to make an overload of enforce
that acts just like in your example, but is taken off with bounds
checking. Then it would not violate safety any more than arrays
do, yet could be compiled to as efficient a release build as the
contract version, if needed.
More information about the Digitalmars-d-learn
mailing list