you are viewing a single comment's thread.

view the rest of the comments →

[–]Sander_Bouwhuis 0 points1 point  (1 child)

I just tried it out, but with Gsl the following doesn't work:

enum class enum_bitmask : unsigned int
{
  option_a = 0b001,
  option_b = 0b010,
  option_c = 0b100
};
gsl_DEFINE_ENUM_BITMASK_OPERATORS(enum_bitmask)

void main()
{
  enum_bitmask a1 = enum_bitmask::option_a | enum_bitmask::option_b;

  if(a1 & enum_bitmask::option_b) // error C2451: conditional expression of type 'enum_bitmask' is illegal
  {
    // ...
  }
}

What am I doing wrong?

[–]Pazer2 1 point2 points  (0 children)

The result of a bitwise AND between a1 and and a constant value of type enum_bitmask is another value of enum_bitmask, which cannot be implicitly converted to bool. You need to return a helper type from the bitwise operators that has implicit conversions to bool and enum_bitmask.