#undef NDEBUG #include "Utils.hpp" #include #include #include #include #include std::locale utf8loc(std::locale(), new std::codecvt_utf8); using namespace Utils; using namespace std; enum class Color { RED = 1, GREEN = 2, YELLOW = 3, BLUE = 4, MAGENTA = 5, CYAN = 6 }; wstring to_wstring(Color e ) { static const map m = { {1, L"RED"}, {2, L"GREEN"}, {3, L"YELLOW"}, {4, L"BLUE"}, {5, L"MAGENTA"}, {6, L"CYAN"} }; return m.at(static_cast(e)); } wostream &operator<<(wostream& os, Color e ) { return os << to_wstring(e); } Color combine_colors(Color const c1, Color const c2) noexcept { int const i1 = static_cast(c1); int const i2 = static_cast(c2); int const RESULT = i1 | i2; Color const RETURN_COLOR = static_cast(RESULT); return RETURN_COLOR; } int main(int argc, char **argv) { setlocale(LC_ALL, "en_US.UTF-8"); wcout.imbue(utf8loc); wcin.imbue(utf8loc); Color c1 = Color::BLUE; wcout << L"c1: " << to_wstring(c1) << endl; wcout << L"RED: " << to_wstring(Color::RED) << endl; wcout << L"combineColors(c1, RED): " << to_wstring(combine_colors(c1, Color::RED)) << endl; Color const c2 = Color::GREEN; wcout << L"combineColors(c1, c2): " << to_wstring(combine_colors(c1, c2)) << endl; if (c1 == c2) { wcout << L"c1 == c2" << endl; } else { wcout << L"c1 != c2" << endl; } c1 = c2; if (c1 == c2) { wcout << L"c1 == c2" << endl; } else { wcout << L"c1 != c2" << endl; } Color const BAD = static_cast(7); wcout << L"bad: " << to_wstring(BAD) << endl; return 0; }