NotNull pointers
Simen Kjaeraas
simen.kjaras at gmail.com
Mon Aug 29 13:41:19 PDT 2011
On Mon, 29 Aug 2011 22:22:52 +0200, Walter Bright
<newshound2 at digitalmars.com> wrote:
> For the latest dmd,
> https://github.com/D-Programming-Language/dmd/commit/1193f7828b444056c943742daae0a5ccf262272e
> ,
> I've implemented the ability to disable default initialization. This
> makes it practical to implement a library based "NotNull" type without a
> special syntax for it. The rationale for this is (rather than making it
> builtin) one can now build any type that is a restricted subset of
> another type. I suspect that a non-null type is just scratching the
> surface of this ability.
Awesome!
How does it deal with arrays whose elements have no default constructor?
I believe increasing the length of such an array should be an error (which
likely also excludes decreasing it except for slices).
> I do think that the "this() @disable;" is an ugly syntax, and I cringe
> when seeing it. But I can't think of anything better. It does make
> logical sense given the existence of default construction syntax and the
> @disable, so in a sense it is just connecting existing dots, which has a
> compelling value.
I think it's perfect, you just need the words to trade places:
@disable this(); One could argue that @disabled would work better, but
that's a can of worms I'm not touching.
Really looking forward to trying this out.
--
Simen
More information about the Digitalmars-d
mailing list