bitwise: use free equality operator for bitfields
This commit is contained in:
parent
5cdabcb583
commit
fd1fda9145
14
bitwise.hpp
14
bitwise.hpp
@ -156,16 +156,24 @@ namespace cruft {
|
|||||||
constexpr ValueT get (void) const
|
constexpr ValueT get (void) const
|
||||||
{
|
{
|
||||||
auto const MASK = ~(~0u << SizeV);
|
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;
|
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>
|
template <typename ValueT, size_t Offset, size_t Size>
|
||||||
std::ostream& operator<< (std::ostream &os, bitfield<ValueT,Offset,Size> const &val)
|
std::ostream& operator<< (std::ostream &os, bitfield<ValueT,Offset,Size> const &val)
|
||||||
|
Loading…
Reference in New Issue
Block a user