#include <iostream>
using namespace std;
//Sometimes it is useful to have an inline IIF for the preprocessor
#define IIF(bit, t, f) IIF_ ## bit(t, f)
#define IIF_0(t, f) f
#define IIF_1(t, f) t
//The idea can be extended...
#define PPCHOICE(choice, ch1, ch2, ch3, ch4) PPCHOICE_ ## choice(ch1, ch2, ch3, ch4)
#define PPCHOICE_EN(ch1, ch2, ch3, ch4) ch1
#define PPCHOICE_FR(ch1, ch2, ch3, ch4) ch2
#define PPCHOICE_SP(ch1, ch2, ch3, ch4) ch3
#define PPCHOICE_GR(ch1, ch2, ch3, ch4) ch4
#define GREETING_EN "Hello World!"
#define GREETING_FR "Bonjour Monde!"
#define GREETING_SP "Hola Mundo!"
#define GREETING_GR "Hallo Welt!"
// I am not saying that this is the best way to do things
// only trying to give an example of how this may be used.
int main() {
cout << IIF(0, "True", "False") << endl;
cout << PPCHOICE(EN, GREETING_EN, GREETING_FR, GREETING_SP, GREETING_GR) << endl;
cin.get();
return 0;
}
Preprocessor IIF
Page 1 of 10 Replies - 79 Views - Last Post: 10 August 2008 - 01:22 PM
#1
Preprocessor IIF
Posted 10 August 2008 - 01:22 PM
Description: Sometimes it is useful to have an inline IIF to use in the preprocessor rather than having to use #if.
Page 1 of 1

New Topic/Question
Reply



MultiQuote

|