bitwise: add explicit accessor get

This commit is contained in:
Danny Robson 2019-02-03 14:16:58 +11:00
parent 5d76fb7792
commit 5218fa8165

View File

@ -153,15 +153,16 @@ namespace cruft {
static_assert (SizeV > 0); static_assert (SizeV > 0);
static_assert (OffsetV + SizeV <= sizeof (ValueT) * 8); static_assert (OffsetV + SizeV <= sizeof (ValueT) * 8);
decltype(auto) constexpr ValueT get (void) const
operator+ () const { return +value; }
operator auto() const
{ {
auto const MASK = (1u << SizeV) - 1u; auto const MASK = ~(~0u << SizeV);
return (value >> OffsetV) & MASK; return (value >> OffsetV) & MASK;
} }
operator auto() const { return get (); }
decltype(auto) operator+ () const { return +get (); }
ValueT value; ValueT value;
}; };