RFC: scope and borrowing
via Digitalmars-d
digitalmars-d at puremagic.com
Sun Sep 21 02:11:03 PDT 2014
On Sunday, 21 September 2014 at 03:39:24 UTC, Walter Bright wrote:
> I think it's a well thought out proposal. Thanks for doing this!
>
> A couple thoughts:
>
> 1. const can be both a storage class and a type constructor.
> Scope is only a storage class. The scope(int) syntax implies
> scope is a type constructor, too.
>
> const int* a; // const used as storage class
> const(int*) b; // const used as type constructor
>
> The type constructor syntax should be disallowed for const.
(... disallowed for _scope_, I assume)
I originally intended it to be part of the type. Ivan Timokhin
pointed out severe problems with that [1], so I removed it from
the proposal. The syntax is a remainder of that.
But before I remove it too, I have a question: Will it still be
possible to use the storage class syntax for members of
aggregates?
struct S {
scope!myAllocator int* p;
}
>
> 2. I think there is quite a bit of overlap between scope and
> ref. Essentially, ref does everything scope does, except deal
> with classes. I'm not terribly comfortable with such a large
> overlap, it implies something is wrong. I don't have an answer
> at the moment.
I also see the overlap, but there are also large differences to
the point that I cannot see how the two concepts could be
unified. For one, `ref` with classes (and reference types in
general) is troublesome, and would introduce a double indirection
for borrowing, when a simple copy of the reference would be
sufficient. Then, `scope` could also for non-reference types.
File handles come to mind, which are often integers, and just
need to be copied.
[1]
http://forum.dlang.org/thread/etjuormplgfbomwdrurp@forum.dlang.org?page=3#post-lusirm:2421d9:241:40digitalmars.com
More information about the Digitalmars-d
mailing list