DIP29
Title: | Unique Pointers |
---|---|
DIP: | 29 |
Version: | 1 |
Status: | Draft |
Created: | 2013-02-28 |
Last Modified: | 2013-02-28 |
Language: | D2 |
Breaks: | Nothing, it enables code that doesn't compile at the moment |
Links: | Discussion on github |
Contents
Abstract
Currently, pointers cannot be converted to and from shared and immutable without an explicit and unsafe cast. Unique pointers can be implicitly cast to and from shared and immutable in safety. A unique pointer can be discovered by examining the expression that generated the pointer.
Rationale
Requiring switching to unsafe code to do routine things like create immutable references is a glaring problem. By recognizing unique pointers much of this can be done safely. More advanced analysis can uncover more cases that can be done safely.
Expression Case 1: ptr+offset
If an expression ptr+offset yields a pointer, that expression is convertible iff ptr is convertible.
Expression Case 2: ptr-offset
If an expression ptr-offset yields a pointer, that expression is convertible iff ptr is convertible.
Expression Case 3: new T
This is convertible if T is convertible. (Not sure this is completely true.)
A lot more work is needed to enumerate all the cases.
Copyright
This document has been placed in the Public Domain.