{"id":228,"date":"2026-02-27T14:06:21","date_gmt":"2026-02-27T14:06:21","guid":{"rendered":"https:\/\/myjetsonnano.perseus314.com\/?p=228"},"modified":"2026-02-27T14:07:15","modified_gmt":"2026-02-27T14:07:15","slug":"enum-class-for-bit-flags","status":"publish","type":"post","link":"https:\/\/myjetsonnano.perseus314.com\/index.php\/2026\/02\/27\/enum-class-for-bit-flags\/","title":{"rendered":"enum class for bit flags"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\"><code>enum class<\/code> as Bit Flags<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>enum class Problem : uint8_t\n{\n    None        = 0,\n    FileError   = 1 &lt;&lt; 0,   \/\/ 1\n    ParseError  = 1 &lt;&lt; 1,   \/\/ 2\n    Timeout     = 1 &lt;&lt; 2,   \/\/ 4\n    Network     = 1 &lt;&lt; 3    \/\/ 8\n};<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Enable Bitwise Operators<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>inline Problem operator|(Problem a, Problem b)\n{\n    return static_cast&lt;Problem>(\n        static_cast&lt;uint8_t>(a) |\n        static_cast&lt;uint8_t>(b)\n    );\n}\n\ninline Problem operator&amp;(Problem a, Problem b)\n{\n    return static_cast&lt;Problem>(\n        static_cast&lt;uint8_t>(a) &amp;\n        static_cast&lt;uint8_t>(b)\n    );\n}\n\ninline Problem&amp; operator|=(Problem&amp; a, Problem b)\n{\n    a = a | b;\n    return a;\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">Returning Combined Problems<\/h2>\n\n\n\n<pre class=\"wp-block-code\"><code>Problem checkStuff()\n{\n    Problem result = Problem::None;\n\n    if (!fileOk)\n        result |= Problem::FileError;\n\n    if (!parsed)\n        result |= Problem::ParseError;\n\n    return result;\n}<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>enum class as Bit Flags Enable Bitwise Operators Returning Combined Problems<\/p>\n","protected":false},"author":1,"featured_media":229,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[17,9],"tags":[],"class_list":["post-228","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-c","category-software"],"_links":{"self":[{"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/posts\/228","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/comments?post=228"}],"version-history":[{"count":1,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/posts\/228\/revisions"}],"predecessor-version":[{"id":230,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/posts\/228\/revisions\/230"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/media\/229"}],"wp:attachment":[{"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/media?parent=228"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/categories?post=228"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/myjetsonnano.perseus314.com\/index.php\/wp-json\/wp\/v2\/tags?post=228"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}