"Daniel Keep" <daniel.keep.li...@gmail.com> wrote in message 
news:gmqmhk$2mb...@digitalmars.com...
>
> How do you propose to write a template implementing nullable types when
> you aren't ALLOWED to use null?  You'd have to start casting around
> between integers and references, which is arguably worse than just
> supporting nullable types.
>

Devil's advocate:
---------------
struct Nullable(T)
{
   private T value; // Assuming "X x;" means "X x = new X();"
   private bool _isNull=true;

   void set(T val) {
       value = val;
       _isNull = false;
   }
   T get() {
       if (_isNull)
            throw NullableTypeException("value is null")
       else
            return value;
   }
   void makeNull() {
       _isNull = true;
   }
   bool isNull() {
       return _isNull;
   }
}
---------------

But admittedly, it's a kludge and vastly inferior to a nice well-implemented 
"X? x;" at the language level.


Reply via email to