On Monday, 21 September 2015 at 11:01:27 UTC, ZombineDev wrote:
I prefer library-defined smart pointers than language magic, because you can easily modify them to fit your needs. What D needs is a way to enforce that the user can't get unmanaged references to the underlying object managed by the smart pointer.
That's ok. I've done that in my own prototype library by having a "movingptr!T" returned by doing "move(someuniqueptr)" and "borrowptr!T" returned by "borrow(...)". But checking is limited to runtime asserts in destructors in debug builds.
It is ok as a runtime hack... but not a competitive solution.
The killer way to implement this in D is to NOT add complexity in the compiler (and to change the whole language to some imaginable perfect correct memory management system), but to add away for the library writers to write extensible CTFE checkers that enforce the smart pointer invariants at compile-time.
That is most likely even more work than creating a language solution?