Fix Issue 9183 - Add a Nullable.get(x) overload#5695
Conversation
|
Thanks for your pull request, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon. Some tips to help speed things up:
Bear in mind that large or tricky changes may require multiple rounds of review and revision. Please see CONTRIBUTING.md for more information. Bugzilla references
|
std/typecons.d
Outdated
| /// ditto | ||
| @property get(T)(T datum) @safe pure nothrow | ||
| { | ||
| if (isNull) |
There was a problem hiding this comment.
Nitpick: return isNull ? datum : _value;
std/typecons.d
Outdated
| } | ||
|
|
||
| /// ditto | ||
| @property get(T)(T datum) @safe pure nothrow |
There was a problem hiding this comment.
I tried, but I get a weird error and I don't understand exactly why :
std/typecons.d(2531): Error: pure function 'std.typecons.Nullable!(VariantN!32LU).Nullable.get' cannot call impure destructor 'std.variant.VariantN!32LU.VariantN.~this'
std/typecons.d
Outdated
| } | ||
|
|
||
| /// ditto | ||
| @property get(T datum) @safe pure nothrow |
There was a problem hiding this comment.
This could be const as well?
You could get around the impure error by templating get and thus letting the compiler do the work.
JackStouffer
left a comment
There was a problem hiding this comment.
Looks good, though I would change datum to default to be in line with other libraries/languages.
|
@JackStouffer |
|
|
std/typecons.d
Outdated
| } | ||
|
|
||
| /// ditto | ||
| @property get(T)(T datum) inout @safe pure nothrow |
There was a problem hiding this comment.
You need to mark datum as inout as well, or else the return will always be const (because of the inferred type of the ?: expression).
There was a problem hiding this comment.
Can you change the T to U as it masks the overarching template type from the Nullable struct?
|
My only criticism is that the function name is only passingly related to what it actually does. I Would suggest something more descriptive like |
|
@MetaLang I think that problem is partially addressed by this being consistent with the same type of function in Python (and I think Ruby). |
No description provided.