return val if

Steven Schveighoffer schveiguy at gmail.com
Sun Mar 22 20:18:13 UTC 2020


On 3/22/20 3:04 PM, Dennis wrote:
> 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 think it's essentially the D way to do that, but it appears that the 
behavior of glib is to return a value instead.

The exact behavior there is not reproducible in D AFAIK without mixins.

-Steve


More information about the Digitalmars-d-learn mailing list