On Sunday, 22 March 2020 at 18:48:32 UTC, Abby wrote:
Is there a way to create a template that would do the same is
glib
g_return_val_if_fail()
(https://developer.gnome.org/glib/stable/glib-Warnings-and-Assertions.html#g-return-val-if-fail)
I'm not famililar with glib, but the description:
If expr evaluates to FALSE, the current function should be
considered to have undefined behaviour (a programmer error).
Sounds a lot like:
```
assert(expr);
```
I was hoping something like this would work
template returnValIfFail(alias expr, alias val)
{
if(expr) return val;
}
It would have to be a string mixin, you can't inject a return
statement otherwise.
The thing is, why do you want that? It seems shorter to just
write it out:
if(expr) return val;
debug if(expr) return val;
returnValIfFail!(expr, val);