Skip to main content
Post Made Community Wiki by PleaseStand
"You can use std::boolalpha instead of ?:. – Jon Purdy"
Source Link
PleaseStand
  • 5.6k
  • 2
  • 23
  • 44

Here is a solution for C++ based on operator overloading. It relies on implicit conversion from an enum to an int.

#include <iostream>

enum X {};
bool operator==(X x, int y)
{
    return true;
}

int main()
{
    X x;
    std::cout << (std::boolalpha << (x == x+2) ? "true" : "false") << std::endl;
    return 0;
}

Here is a solution for C++ based on operator overloading. It relies on implicit conversion from an enum to an int.

#include <iostream>

enum X {};
bool operator==(X x, int y)
{
    return true;
}

int main()
{
    X x;
    std::cout << ((x == x+2) ? "true" : "false") << std::endl;
    return 0;
}

Here is a solution for C++ based on operator overloading. It relies on implicit conversion from an enum to an int.

#include <iostream>

enum X {};
bool operator==(X x, int y)
{
    return true;
}

int main()
{
    X x;
    std::cout << std::boolalpha << (x == x+2) << std::endl;
    return 0;
}
Source Link
PleaseStand
  • 5.6k
  • 2
  • 23
  • 44

Here is a solution for C++ based on operator overloading. It relies on implicit conversion from an enum to an int.

#include <iostream>

enum X {};
bool operator==(X x, int y)
{
    return true;
}

int main()
{
    X x;
    std::cout << ((x == x+2) ? "true" : "false") << std::endl;
    return 0;
}