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

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -