Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

std.typecons.nullable and nullableRef functions #9959

Open
dlangBugzillaToGithub opened this issue Mar 2, 2013 · 0 comments
Open

std.typecons.nullable and nullableRef functions #9959

dlangBugzillaToGithub opened this issue Mar 2, 2013 · 0 comments

Comments

@dlangBugzillaToGithub
Copy link

bearophile_hugs reported this on 2013-03-02T13:37:47Z

Transfered from https://issues.dlang.org/show_bug.cgi?id=9637

Description

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.
@LightBender LightBender removed the P4 label Dec 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants