C++ pattern matching is coming
ryuukk_
ryuukk.dev at gmail.com
Mon Oct 24 20:48:37 UTC 2022
On Monday, 24 October 2022 at 18:18:52 UTC, Walter Bright wrote:
> 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" :-/
It's never too late, dmd could have a mechanism to fix/convert
code automatically
More information about the Digitalmars-d
mailing list