Concern about the ref return argument and scope

deadalnix via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 28 09:50:08 PST 2015


On Wednesday, 28 January 2015 at 07:04:43 UTC, Manu wrote:
> Lifetime 'this' probably also needs to exist, for objects that 
> return
> members by ref.

Well, as far as I'm concerned, this is a parameter like another. 
There is just syntax sugar to pass it around implicitely.

> I think this covers practically all useful cases. What problem 
> cases
> remain? Returning a global by ref?
> I should think that can also be supported easily enough; return 
> by ref
> without lifetime implies global lifetime, and the function would
> compile error when trying to return a local/member/argument 
> that way.
>

global lifetime by default for ref return do not make any sense 
IMO. It is very uncommon to return a ref to something you just 
allocated on the GC (why don't you return it directly ?) or to a 
static.

If we can make lifetime explicit, I see no reason not to add a 
way to specify infinite lifetime.

> I agree with you. I'm completely unsatisfied with the current
> proposals, or 'plans', as I think they have been promoted.

Yup, I'm afraid that once they are in the wild, it is gonna solve 
the problem short term, but only one aspect of it, and ultimately 
get in the way to a more general solution.


More information about the Digitalmars-d mailing list