[Issue 9637] New: std.typecons.nullable and nullableRef functions

d-bugmail at puremagic.com d-bugmail at puremagic.com
Sat Mar 2 13:37:48 PST 2013


http://d.puremagic.com/issues/show_bug.cgi?id=9637

           Summary: std.typecons.nullable and nullableRef functions
           Product: D
           Version: D2
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: enhancement
          Priority: P2
         Component: Phobos
        AssignedTo: nobody at puremagic.com
        ReportedBy: bearophile_hugs at eml.cc


--- Comment #0 from bearophile_hugs at eml.cc 2013-03-02 13:37:47 PST ---
Spinoff of Issue 9265

I suggest to add to std.typecons two small functions that help the creation of
a Nullable and NullableRef:


import std.typecons;
void main() {
    int x;
    auto n1 = Nullable!int(x);
    auto n2 = NullableRef!int(&x);
    auto n3 = nullable(x); // missing
    auto n4 = nullableRef(&x); // missing
}


This gets handy when the type of the item is complex:

auto n = nullable(data);

Instead of:

auto n = Nullable!(immutable int[4])(data);

- - - - - - - - - - - -

Note: maybe it's possible to support Nullable(T, T nullValue) like this:

auto n5 = nullable!(int.max)(x);

But maybe for simplicity it's better to not support this.

-- 
Configure issuemail: http://d.puremagic.com/issues/userprefs.cgi?tab=email
------- You are receiving this mail because: -------


More information about the Digitalmars-d-bugs mailing list