This patch contains a new container class, SmallEnumSet, and unit tests for it.<div><br></div><div>SmallEnumSet is inspired by SmallVector and the other "small" sets in ADT.</div><div><br></div><div>The keys of the set are enumeration constants, which range from 0 to some maximum value which is known at compile time. Internally, SmallEnumSet maintains a fixed-length bit vector, so that membership in the set is represented by a single bit per possible key.</div>
<div><br></div><div>Traditionally in C and C++ this sort of thing is done via a "flags" field. SmallEnumSet has a number of advantages over using flags:</div><div><ul><li>It's type safe.</li><li>It has a set-like interface, so you can use "add", "contains" and other set methods.</li>
<li>It isn't limited to 32 flags or whatever the size of an integer may be.</li><li>The keys can be sequentially-numbered enumeration constants, such as produced by an enum statement with default initialization - you don't have to initialize your enum constants to single-bit values such as "(1 << 5)" or "0x00000800", nor do you have to update all of the initializers if you want to insert a new constant in the middle of the sequence.</li>
</ul><div>At the same time, SmallEnumSet retains many of the advantages of an integer flags field - it allocates no memory, and can efficiently be passed or returned by value between functions. All of the methods of the class can be optimized down to essentially the same code you would write if you were using flags.</div>
<div><br></div><div>(I actually wrote this about 6 months ago, and I've been using it quite a bit in my own code, but I didn't want to submit a patch until I could also submit the unit tests - which was one of my motivations for doing the unit test work.)</div>
</div><div><br></div><div>-- <br>-- Talin<br>
</div>