Commit 1e4b0435 authored by Clemens Backes's avatar Clemens Backes Committed by Commit Bot

[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: 's avatarMichael Lippautz <mlippautz@chromium.org>
Cr-Commit-Position: refs/heads/master@{#66451}
parent e7fa1fbf
......@@ -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}; }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment