How to "scope"?

Martin martinbbjerregaard at gmail.com
Mon Feb 3 09:50:32 PST 2014


On Monday, 3 February 2014 at 17:43:09 UTC, Namespace wrote:
> On Monday, 3 February 2014 at 17:32:07 UTC, Martin wrote:
>> Oops, I of course meant:
>>
>> static Test createFromString(string str)
>> {
>>  return new Test(str);
>> }
>
> You _can_ use scoped but it may allocate way to much and it's 
> ugly to use:
> http://dlang.org/phobos/std_typecons.html#.scoped
>
> AFAIK scope'd classes was only deprecated because it _can_ be 
> solved with a library solution and scope is/was not fully 
> implemented. So it was more easy to depecate it and replace it 
> with a library solution, as to implement scope as it stand in 
> the docs.

I'm aware of "scoped", that's why I used this specific example. 
How do you use scoped on a function that returns a new instance 
of some object?

auto obj = scoped(functionThatReturnsNewObject());

That obviously doesn't work.


More information about the Digitalmars-d-learn mailing list