[kutil] Add bitfiled::has() for non-marked enums

Added a simple helper function for testing non-marked enum bitfields.
This commit is contained in:
Justin C. Miller
2021-07-25 23:30:37 -07:00
parent b88cd1d41f
commit ec9e34c970

View File

@@ -86,6 +86,16 @@ template <typename E>
constexpr typename std::enable_if<is_enum_bitfield(E{}),bool>::type
operator && (E rhs, E lhs) { return (rhs & lhs) == lhs; }
/// Generic 'has' for non-marked bitfields
template <typename E, typename F>
constexpr bool has(E set, F flags)
{
return
(static_cast<typename integral<E>::type>(set) &
static_cast<typename integral<F>::type>(flags)) ==
static_cast<typename integral<F>::type>(flags);
}
} // namespace bitfields
} // namespace kutil