Created
May 5, 2017 13:45
-
-
Save code-disaster/3ff001190e1d798e5de1c5641b81dd67 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
A hack found at stackoverflow.com to raise a compiler warning if a non-boolean | |
expression is silently converted to bool in conditional statements. | |
*/ | |
struct not_a_bool {}; | |
template< typename T > | |
not_a_bool ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(T /*value*/) | |
{ | |
return not_a_bool(); | |
} | |
bool ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(bool value); | |
#define if(x) if(ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(x)) | |
#define while(x) while(ERROR_CONDITIONAL_EXPRESSION_IS_NOT_BOOL(x)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment