Note that the use of macros is heavily frowned upon by many programmers of C++, since macros are very powerful and have the ability to be frustrating if created improperly. However, if created and used properly and intelligently they can be a major time saver. I don't see another way to get the requested syntax and code space per comparison similar to what you are requesting without compromising the efficiency, code space, or memory used by your program. Your goal was to have a shortcut, and most of the other solutions presented here are longer than what you originally wanted to shorten. Here are macros which will do so safely, assuming you are comparing an integer:
#pragma once
int unused;
#define IFNOTIN2(x, a, b) \
if (unused = (x) && unused != (a) && unused != (b))
#define IFNOTIN3(x, a, b, c) \
if (unused = (x) && unused != (a) && unused != (b) && unused != (c))
#define IFNOTIN4(x, a, b, c, d) \
if (unused = (x) && unused != (a) && unused != (b) && unused != (c) && unused != (d))
#define IFNOTIN5(x, a, b, c, d, e) \
if (unused = (x) && unused != (a) && unused != (b) && unused != (c) && unused != (d) && unused != (e))
Here is a working tested example with one of the above macros:
#include <iostream>
#include "macros.h"
int main () {
std::cout << "Hello World\n";
for (int i = 0; i < 100; i ++) {
std::cout << i << ": ";
IFNOTIN4 (i, 7, 17, 32, 87) {
std::cout << "PASSED\n";
} else {
std::cout << "FAILED\n";
}
}
std::cin.get();
return 0;
}
Note that the macros should go in a header file that's included wherever you need to use them. Your code will fail to compile if you are already using a variable named 'unused' in your code elsewhere or trying to use these macros to compare something other than an integer. I'm sure you can expand the macros to handle other types of data if that becomes necessary.
Order of operations is preserved by using brackets around all inputs, and the value is saved to a variable before comparison to prevent multiple executions of CPU-intensive code.