RFC: BitMask helper ADT

Saleem Abdulrasool via llvm-commits llvm-commits at lists.llvm.org
Mon Jul 11 18:58:05 PDT 2016


On Tue, Jun 23, 2015 at 4:12 PM, Saleem Abdulrasool <compnerd at compnerd.org>
wrote:

> Hello,
>
> While looking at something unrelated (yay yak-shaving!) ... it came up
> that it may be convenient to actually re-use enumerations as bit masks in
> certain cases (assuming that the values are appropriately disjoint).
>
> The thing is that enum classes are becoming more prevalent, and they are
> not simply usable in logical operations without casting.  The "solution" to
> this is replicate the enumeration.  The helper helps avoid the extensive
> casting by wrapping up the underlying type into a helper that simply
> provides the overloads for the normal (logical) operations.  It would also
> allow the re-use of the enumeration rather than duplicate the values.
>
> The implementation presented here should work with MSVC 2013, clang and
> GCC.  It is more of a proof of concept, that this is possible.  This thread
> is meant to raise the question of: is this a good idea?  Do we want to just
> use unsigned for bit masks instead?
>
> (A thank you goes out to Aaron for a discussion on this idea and help with
> some of the nastier pieces of the metaprogramming here).
>
> One point that I know will most definitely be brought up: the implicit
> boolean conversion.  Yes, its implicit, and yes that was an explicit
> choice.  The problem is that the use of logical operators as conditions is
> pretty extensive, so this conversion operator tends to be involved quite
> often, and would be needed to keep the idiomatic use in place.
>

Seems that this idea came up again.  What does this add to my necromancy
skills?


> --
> Saleem Abdulrasool
> compnerd (at) compnerd (dot) org
>

-- 
Saleem Abdulrasool
compnerd (at) compnerd (dot) org
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160711/7f7effa4/attachment.html>


More information about the llvm-commits mailing list