Modern C++ Won't Save Us

Paul Backus snarwin at gmail.com
Wed Apr 28 00:17:39 UTC 2021


On Tuesday, 27 April 2021 at 23:38:14 UTC, Walter Bright wrote:
>
> As always, when confused about this, rewrite the code in terms 
> of simple ref's and pointers.

I think a large part of the confusion here stems from the fact 
that `scope ref T` behaves very differently from `scope T*`, even 
though `ref T` and `T*` are the same "under the hood."

     @safe:
     static int* betty(scope ref S s) { return s.ptr; } // Error
     static int* veronica(scope S* s) { return s.ptr; } // Ok

Unfortunately, there is no documentation of this distinction in 
the language spec (or anywhere else, as far as I know), so the 
only way anyone can learn about it is through trial and error.


More information about the Digitalmars-d mailing list