First Draft: opUnwrapIfTrue
Walter Bright
newshound2 at digitalmars.com
Fri Mar 13 19:14:32 UTC 2026
Thank you for taking the time to develop this.
This is a bit simpler and doesn't require language changes:
```d
struct Result(T)
{
bool hasValue;
T value;
bool get(out T x)
{
if (hasValue)
{
x = value;
return true;
}
return false;
}
}
void bar(int);
void foo()
{
Result!int r;
int x;
if (r.get(x)) { bar(x); }
}
```
It also can be embedded in an expression and other constructs:
```d
int x;
switch (r.get(x) ? x : x.init)
{
...
}
```
To channel Andrei, destroy!
More information about the dip.development
mailing list