microsoft / yardl

Tooling for streaming instrument data
https://microsoft.github.io/yardl/
MIT License
30 stars 5 forks source link

Fix compilation error with flags #58

Closed johnstairs closed 1 year ago

johnstairs commented 1 year ago

This addresses a compilation error when using flags with a base type that is not int32.

Note that the fix will mean that flags are no longer implicitly convertible to bool, meaning that checks like this will not compile:

if (f & MyFlags::kB) {
 std::cout << "b is set" << std::endl;
}

But unless you know that kB as exactly one bit set, the condition above is potentially incorrect and you should instead write:

if (f.HasFlags(MyFlags::kB)) {
  std::cout << "b is set" << std::endl;
}

or the expanded form:

if ((f & MyFlags::kB) == MyFlags::kB) {
  std::cout << "b is set" << std::endl;
}