News for hackers. Stuff that matters.
Re:Type-safe Bitmasks in C++ by 8xde0wcNwpslOw on Wednesday June 13, 2018 @07:26AM (#17302065)
Bitfields would be, in theory, safer still: no manual bit-twiddling to begin with and also quite straightforward usage. Unfortunately, they are (and I guess will remain) underspecified as far as portability is concerned.

You can, of course, do something similar with member functions, e.g.

  class controller
  {
    unsigned value;
    static constexpr unsigned BTN_A = 0x01;
    ...
  public:
    bool a() const { return value & BTN_A; }
    void a(bool set) { if (set) value |= BTN_A; else value &= ~BTN_A; }
  };
Re:Type-safe Bitmasks in C++ by inetknght on Wednesday June 13, 2018 @09:43AM (#17302930)
This is pretty similar to what I've done in the past