"if not" condition check (for data validation)
Denis
noreply at noserver.lan
Thu Jun 18 17:39:44 UTC 2020
On Thursday, 18 June 2020 at 12:50:35 UTC, Stanislav Blinov wrote:
> No, there isn't a way to write an operator.
OK, first choice eliminated.
On Thursday, 18 June 2020 at 13:57:39 UTC, Dukc wrote:
> No reason to use templates here
>
> pragma(inline, true) auto not(bool cond) { return !cond(); }
I like it. The inline pragma eliminates the extra overhead of the
function call, which was another objective. (And it introduces me
to D's pragmas too.)
Personally, I find this:
if ( not( abra && cadabra )) ...
to be more clear than:
if ( !( abra && cadabra )) ...
I guess it depends on what one is used to. I do recognize that
this would be non-standard for D, but I'm still going to use it
because I find it more readabile.
I should add that this one made me laugh though, giving
flashbacks to that horrible "not speak" of the early 90s:
if ( configfile.isFile.not ) ...
LOL
I've learned multiple things from this posting. Thank you all for
sharing your suggestions.
Denis
More information about the Digitalmars-d-learn
mailing list