bitwise: use free equality operator for bitfields

This commit is contained in:
Danny Robson 2019-02-03 16:38:40 +11:00
parent 5cdabcb583
commit fd1fda9145

View File

@ -156,16 +156,24 @@ namespace cruft {
constexpr ValueT get (void) const
{
auto const MASK = ~(~0u << SizeV);
return (value >> OffsetV) & MASK;
ValueT shifted = value >> OffsetV;
ValueT masked = shifted & MASK;
return masked;
}
operator auto() const { return get (); }
operator ValueT () const { return get (); }
decltype(auto) operator+ () const { return +get (); }
auto operator+ () const { return +get (); }
ValueT value;
};
template <typename OperandT, typename BitfieldT, size_t OffsetV, size_t SizeV>
bool operator== (bitfield<BitfieldT,OffsetV,SizeV> const &a, OperandT const &b)
{
return a.get () == b;
}
template <typename ValueT, size_t Offset, size_t Size>
std::ostream& operator<< (std::ostream &os, bitfield<ValueT,Offset,Size> const &val)