[base] Extend EnumSet
This extends EnumSet by 1) adding element-wise operations (without first creating an EnumSet of that element in the caller), 2) adding arithmetic assignment operators, and 3) adding a subtraction operation which removes all elements in another EnumSet, or a single element. R=mlippautz@chromium.org Change-Id: Ibe694e9e111e506ad09cf9729fa0b0ba38430b79 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/2071874 Commit-Queue: Clemens Backes <clemensb@chromium.org> Reviewed-by: Michael Lippautz <mlippautz@chromium.org> Cr-Commit-Position: refs/heads/master@{#66451}
This commit is contained in:
parent
e7fa1fbffe
commit
1e4b043523
@ -37,10 +37,25 @@ class EnumSet {
|
||||
void RemoveAll() { bits_ = 0; }
|
||||
void Intersect(EnumSet set) { bits_ &= set.bits_; }
|
||||
T ToIntegral() const { return bits_; }
|
||||
|
||||
bool operator==(EnumSet set) const { return bits_ == set.bits_; }
|
||||
bool operator!=(EnumSet set) const { return bits_ != set.bits_; }
|
||||
|
||||
EnumSet operator|(EnumSet set) const { return EnumSet(bits_ | set.bits_); }
|
||||
EnumSet operator&(EnumSet set) const { return EnumSet(bits_ & set.bits_); }
|
||||
EnumSet operator-(EnumSet set) const { return EnumSet(bits_ & ~set.bits_); }
|
||||
|
||||
EnumSet& operator|=(EnumSet set) { return *this = *this | set; }
|
||||
EnumSet& operator&=(EnumSet set) { return *this = *this & set; }
|
||||
EnumSet& operator-=(EnumSet set) { return *this = *this - set; }
|
||||
|
||||
EnumSet operator|(E element) const { return EnumSet(bits_ | Mask(element)); }
|
||||
EnumSet operator&(E element) const { return EnumSet(bits_ & Mask(element)); }
|
||||
EnumSet operator-(E element) const { return EnumSet(bits_ & ~Mask(element)); }
|
||||
|
||||
EnumSet& operator|=(E element) { return *this = *this | element; }
|
||||
EnumSet& operator&=(E element) { return *this = *this & element; }
|
||||
EnumSet& operator-=(E element) { return *this = *this - element; }
|
||||
|
||||
static constexpr EnumSet FromIntegral(T bits) { return EnumSet{bits}; }
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user