Playing with ranges and ufcs

Jonathan M Davis jmdavisProg at gmx.com
Wed Feb 27 15:57:58 PST 2013


On Thursday, February 28, 2013 00:35:08 bearophile wrote:
> Jonathan M Davis:
> > What it should be doing is using version(assert) to throw a
> > RangeError if the
> > arguments are invalid, but the addition of version(assert) is
> > quite recent
> > (previously, the best that could have been done was to assert).
> 
> Do you mean something like this?
> 
> auto opSlice(size_t i, size_t j) {
> version(assert) {
> if (i > j)
> throw new RangeError("some message here");
> }
> auto retval = this.save;
> retval._index += i;
> return takeExactly(retval, j - i);
> }
> 
> 
> What's the advantage of that compared to using a normal contract?

Because then it more closely matches how arrays work. The only part that 
doesn't is that it's fully tied to -release rather than -noboundschecked.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list