RFC: scope and borrowing
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 25 04:48:17 PDT 2014
On Monday, 25 August 2014 at 10:27:53 UTC, Kagamin wrote:
> Can't scope(int*) on return type be equivalent to
> scope!(a,b)(int*)? How often this is not desired?
You mean as a default?
It would be desired in `chooseStringAtRandom`, but not in the
`findSubstring`, whose returned string shouldn't be limited by
the scope of the needle. If it is made the default, there would
need to be a way to opt out, such as removing an owner.
But note that in the `chooseStringAtRandom` example, it would be
sufficient to declare it as:
scope chooseStringAtRandom(scope(string) a, scope(string) b) {
return random() % 2 == 0 ? a : b;
}
Type deduction would then automatically add `a` and `b` as the
owners, by the rules under "Owner tracking".
More information about the Digitalmars-d
mailing list