www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.bugs - [Issue 9636] New: null initialization for std.typecons.Nullable

reply d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9636

           Summary: null initialization for std.typecons.Nullable
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody puremagic.com
        ReportedBy: bearophile_hugs eml.cc



Currently if I want a Nullable function argument initialized to null I have to
use:

import std.typecons: Nullable;
void foo(Nullable!(immutable int[4]) items = Nullable!(immutable int[4]).init)
{}
void main() {}


Or with a global helper alias:

import std.typecons: Nullable;
alias NullableItems = Nullable!(immutable int[4]);
void foo(NullableItems items = NullableItems.init) {}
void main() {}


But maybe there is a way to modify std.typecons.Nullable so this simpler code
is accepted (or something equally simple):

import std.typecons: Nullable;
void foo(Nullable!(immutable int[4]) items = null) {}
void main() {}

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Mar 02 2013
next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9636


irritate <irritate gmail.com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |irritate gmail.com



https://github.com/D-Programming-Language/phobos/pull/1356

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
Jun 19 2013
prev sibling next sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9636


monarchdodra gmail.com changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |monarchdodra gmail.com




 Currently if I want a Nullable function argument initialized to null I have to
 use:
 
 import std.typecons: Nullable;
 void foo(Nullable!(immutable int[4]) items = Nullable!(immutable int[4]).init)
 {}
 void main() {}
 
 
 Or with a global helper alias:
 
 import std.typecons: Nullable;
 alias NullableItems = Nullable!(immutable int[4]);
 void foo(NullableItems items = NullableItems.init) {}
 void main() {}
 
 
 But maybe there is a way to modify std.typecons.Nullable so this simpler code
 is accepted (or something equally simple):
 
 import std.typecons: Nullable;
 void foo(Nullable!(immutable int[4]) items = null) {}
 void main() {}
I don't think that is acceptable, as you will change the behavior of Nullable!T, if "t = null" already meant something. EG: //---- import std.typecons; void main() { auto n = Nullable!(int*)(null); assert(!n.isNull); assert(n.get() == null); } //---- Arguably, you won't see that very often, but it is plausible for someone to want to be able to have a nullable pointer, whose "non-null" value can itself be null. As a workaround, Nullable-specific "null-token" could work? EG: something along the lines of: EG: enum Nullable {Null} void foo(Nullable!(immutable int[4]) items = Nullable.Null) {} -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 20 2013
prev sibling parent d-bugmail puremagic.com writes:
http://d.puremagic.com/issues/show_bug.cgi?id=9636






 Arguably, you won't see that very often, but it is plausible for someone to
 want to be able to have a nullable pointer, whose "non-null" value can itself
 be null.
Hopefully I'll not see such code :-)
 As a workaround, Nullable-specific "null-token" could work? EG: something along
 the lines of:
 
 EG:
 enum Nullable {Null}
 
 void foo(Nullable!(immutable int[4]) items = Nullable.Null)
 {}
This seems acceptable. -- Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email ------- You are receiving this mail because: -------
Aug 20 2013