On 08/03/2010 01:08 AM, bearophile wrote:
Pelle:

struct NotNull(T) if(is(typeof(T.init !is null))) {

Is this enough?
struct NotNull(T) if (is(T.init is null)) {


      this(T t) {
          enforce(t !is null, "Cannot create NotNull from null");

enforce() is bad, use Design by Contract instead (a precondition with an assert 
inside).

Bye,
bearophile

If NotNull will be in a library, it should probably use enforce, if I have understood things correctly. External input, and all that. I think most of phobos does it like this currently.

Reply via email to