Common scope for function's in{}, out(result){} and body{}
Ilya Yaroshenko via Digitalmars-d
digitalmars-d at puremagic.com
Thu Sep 11 23:41:29 PDT 2014
Hello!
There are local imports available in D.
But if contract programming is necessary there are no common
function scope.
So I suppose D need common scope:
-----------------------------------
auto functionName(Range1, Range2)(Range1 r1, Ranger2)
scope {
import std.range; //imports are allowed
enum MaxLength = 1024; //enums are allowed
immutable A = [0.123, 0.456, 0.789]; // immutable and const
are allowed
bool isOdd (uint i) {return i%2;}
static assert(isInputRange!Range1,
Range1.stringof!~" is not InputRange");
int i; //Error, mutable data disallowed.
immutable length = r1.length; //Error, can't use function
parameters.
}
in {
assert(!r1.empty); // we already know that r1 is InputRange
and function have local imports!
// can use std.range, MaxLength, A, isOdd
}
out(result) {
// can use std.range, MaxLength, A, isOdd
}
body {
// can use std.range, MaxLength, A, isOdd
}
-------------------------------
What do you think?
Best Regards,
Ilya
More information about the Digitalmars-d
mailing list