Chromium Code Reviews| Index: components/sync/base/enum_set.h |
| diff --git a/components/sync/base/enum_set.h b/components/sync/base/enum_set.h |
| index 1000956bc42e58e962eb75bb9357385d77d03764..610f4cd06cf2e3d043499ac5053269c25df5d507 100644 |
| --- a/components/sync/base/enum_set.h |
| +++ b/components/sync/base/enum_set.h |
| @@ -117,21 +117,12 @@ class EnumSet { |
| size_t i_; |
| }; |
| - // You can construct an EnumSet with 0, 1, 2, or 3 initial values. |
| - |
| EnumSet() {} |
| - explicit EnumSet(E value) { Put(value); } |
| - |
| - EnumSet(E value1, E value2) { |
| - Put(value1); |
| - Put(value2); |
| - } |
| - |
| - EnumSet(E value1, E value2, E value3) { |
| - Put(value1); |
| - Put(value2); |
| - Put(value3); |
| + // Recursively chain constructors. Base case is the empty pack. |
| + template <class... T> |
| + EnumSet(E head, T... tail) : EnumSet(tail...) { |
| + Put(head); |
| } |
| // Returns an EnumSet with all possible values. |
| @@ -141,6 +132,13 @@ class EnumSet { |
| return EnumSet(enums); |
| } |
| + // Returns an EnumSet with all the values from start to end, inclusive. |
| + static EnumSet FromRange(E start, E end) { |
| + EnumSet set; |
| + set.PutRange(start, end); |
| + return set; |
| + } |
| + |
| ~EnumSet() {} |
| // Copy constructor and assignment welcome. |
| @@ -155,6 +153,15 @@ class EnumSet { |
| // Adds all values in the given set to our set. |
| void PutAll(EnumSet other) { enums_ |= other.enums_; } |
| + // Adds all values in the given range to our set, inclusive. |
| + void PutRange(E start, E end) { |
| + int endIndexInclusive = ToIndex(end); |
|
pavely
2017/02/23 23:23:03
Could you DCHECK that ToIndex(start) <= ToIndex(en
skym
2017/02/24 18:59:07
Done.
|
| + for (int current = ToIndex(start); current <= endIndexInclusive; |
| + current++) { |
| + enums_.set(current); |
| + } |
| + } |
| + |
| // There's no real need for a Retain(E) member function. |
| // Removes all values not in the given set from our set. |