C++ pattern matching is coming
Walter Bright
newshound2 at digitalmars.com
Mon Oct 24 18:18:52 UTC 2022
There's a misunderstanding here. @live *does* work in @safe code, and confers
benefits.
I oversimplified things by talking about `free`. Of course, `free()` is @system
and is not callable from @safe code. But what I am *really* talking about is
when a pointer is passed as an argument to a function, is it being "moved" or
"copied"?
If it is "copied", that means the caller retains ownership of the pointer. If it
is "moved", the caller transfers ownership to the callee. What the callee does
with the pointer that was transferred to it is not relevant to the caller.
So,
1. void foo(int* p) => argument is moved to foo(), caller can no longer use it
2. void foo(scope int* p) => argument is copied to foo(), caller retains ownership
If we change the annotations to:
1. void foo(owner int* p) => argument is moved to foo()
2. void foo(borrow int* p) => argument is copied to foo()
it means the same thing. This is why dip1000 is foundational to implementing an
ownership/borrowing system.
move == owner == notscope
copy == borrow == scope
If I was smarter, scope would have been spelled "borrow" :-/
More information about the Digitalmars-d
mailing list