another cool RTInfo trick - i want in runtime
Michel Fortin
michel.fortin at michelf.ca
Thu Jan 16 16:46:03 PST 2014
On 2014-01-17 00:03:19 +0000, "Meta" <jared771 at gmail.com> said:
> On Thursday, 16 January 2014 at 23:56:14 UTC, Adam D. Ruppe wrote:
>> // use it! notice that it is notnull already
>> auto na = create!A();
>
> That's neat. Didn't Andrei mention something about wanting new to be
> removed from the language and replaced with a library solution using
> allocators? If that were the case, it'd be pretty easy to enforce that
> class allocators return NotNull!T. It'd get rid of nullable references
> without needing a breaking language change.
In one C++ project of mine I have a make_new< T >(args...) template
function that does exactly that. Pretty neat.
The biggest downside to such an approach is that you're creating your
own meta-language on top of the regular language (replacing the
language syntax with your own). But it cannot really be avoided if you
want NotNull to be usable. The next language facility you might have to
duplicate is the cast (to keep the not-null "qualifier" when casting).
Then maybe you'll want it to play nice with other the other "qualifier"
type template Rebindable.
--
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca
More information about the Digitalmars-d
mailing list