RFC: scope and borrowing
via Digitalmars-d
digitalmars-d at puremagic.com
Mon Aug 25 04:27:10 PDT 2014
On Monday, 25 August 2014 at 10:06:12 UTC, Rikki Cattermole wrote:
> Have you considered what happens when you cast away scope?
> I didn't read anything about that, unless I missed something.
Right, this should be specified. But it's fairly obvious what
would happen: you lose the safety guarantees (=> @system), and
you're responsible to make sure you don't get dangling
references. You'd basically get what you have with normal
pointers. I don't think it has any deeper implications than that,
but I'm not sure there aren't any obscure optimizations the
compiler could make based on scope. If there are, it's no
different from casting away const, in this respect.
>
> I do have to ask this, because what if you wanted to optionally
> return a scoped reference?
Well, it's part of the return type, so it's either scoped, or it
isn't. You could return a tuple with a scoped and a non-scoped
pointer, though.
If it's only about returning a non-scoped pointer from a function
with a scoped return type, that's fine, because it's adding
scope, not removing it. (Use case: ScopeBuffer.)
More information about the Digitalmars-d
mailing list