How to #define if in C++ to be python-like -
i know can define like
#define less(x, y) if(x < y)
so wonder can define if
in c++ python-like template or not? such as
if x < y: something
instead of if(x < y) something
to put shortly - no.
from cplusplus.com:
when preprocessor encounters directive, replaces occurrence of identifier in rest of code replacement. replacement can expression, statement, block or anything. preprocessor not understand c++, replaces occurrence of identifier replacement.
what want
#define if(x):(y) if(x){##y##};
nevertheless, colon keyword , can't used identifier, breaks macro definition. there's no way escape it.
Comments
Post a Comment