[Issue 5115] std.typecons.scoped problems

d-bugmail at puremagic.com d-bugmail at puremagic.com
Wed Dec 19 09:15:46 PST 2012


http://d.puremagic.com/issues/show_bug.cgi?id=5115


Dmitry Olshansky <dmitry.olsh at gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |dmitry.olsh at gmail.com


--- Comment #12 from Dmitry Olshansky <dmitry.olsh at gmail.com> 2012-12-19 09:15:42 PST ---
(In reply to comment #11)
> 
> There is another problem. You may want to pass the instance to another
> function, which is ok since the type will still be alive during that call:
> 
> class C { }
> void func(C c) { }
> void main()
> {
>     auto c = scoped!C();
>     func(c);  // ok, c is still alive here
> }
> 
> Disabling implicit conversion (maybe by using your ProxyOf mixin) might be ok,
> but then we can no longer pass the instance around because `Scoped` is a
> voldemort type hidden inside the `scoped` function. E.g.:
> 
> class C { }
> void func(C c) { }
> void funcScoped(??? c) { }  // param needs to be a proper type
> void main()
> {
>     auto c = scoped!C();  // voldemort type
>     func(c);  // error, no implicit conversion
>     funcScoped(c);  // would be ok if we knew what type c was
> }
> 
> So if we disable implicit conversion we should probably introduce a Scoped type
> instead of a voldemort, so we can write:
> 
> void funcScoped(ref Scoped!C c) { }


Even more interesting is emplacing inside of class instance (to avoid pointer
overhead while modeling composition):

class A{//A makes sure b & c are not escaped
   Scoped!B b;
   Scoped!C c;
}

Overall I think voldemort types are overpriced.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list