Any idea? The purpose of that code snippet is to see if the spam variable concludes of NOTHING, and if so, says Screw you. I don't use if statements as switch statements are better.
The reason why you can't do it in C and C++ is that they "see" arrays as pointers, so when you compare them, you actually compare two numbers representing the arrays' addresses and not their contents.
And if you use std::string, it simply doesn't work with switch(), although it should. I guess this is because it's not a built-in type.
struct A
{
constexpr A( int i ) : a(i), b(i*2) {}
constexproperatorint () const { return a + b ; }
private:
int a ;
int b ;
};
int main()
{
constexpr A a[] = { {2}, {5}, {12} } ;
int i ;
std::cin >> i ;
switch(i)
{
case a[0] :
// ...
break ;
case a[1] :
// ...
break ;
case a[2] :
// ...
break ;
default :
// ...
;
}
}