OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef COMPONENTS_SYNC_BASE_ENUM_SET_H_ | 5 #ifndef COMPONENTS_SYNC_BASE_ENUM_SET_H_ |
6 #define COMPONENTS_SYNC_BASE_ENUM_SET_H_ | 6 #define COMPONENTS_SYNC_BASE_ENUM_SET_H_ |
7 | 7 |
8 #include <bitset> | 8 #include <bitset> |
9 #include <cstddef> | 9 #include <cstddef> |
10 #include <string> | 10 #include <string> |
(...skipping 23 matching lines...) Expand all Loading... |
34 // std::bitset<> with stronger type enforcement, more descriptive | 34 // std::bitset<> with stronger type enforcement, more descriptive |
35 // member function names, and an iterator interface. | 35 // member function names, and an iterator interface. |
36 // | 36 // |
37 // If you're working with enums with a small number of possible values | 37 // If you're working with enums with a small number of possible values |
38 // (say, fewer than 64), you can efficiently pass around an EnumSet | 38 // (say, fewer than 64), you can efficiently pass around an EnumSet |
39 // for that enum around by value. | 39 // for that enum around by value. |
40 | 40 |
41 template <typename E, E MinEnumValue, E MaxEnumValue> | 41 template <typename E, E MinEnumValue, E MaxEnumValue> |
42 class EnumSet { | 42 class EnumSet { |
43 public: | 43 public: |
44 typedef E EnumType; | 44 using EnumType = E; |
45 static const E kMinValue = MinEnumValue; | 45 static const E kMinValue = MinEnumValue; |
46 static const E kMaxValue = MaxEnumValue; | 46 static const E kMaxValue = MaxEnumValue; |
47 static const size_t kValueCount = kMaxValue - kMinValue + 1; | 47 static const size_t kValueCount = kMaxValue - kMinValue + 1; |
48 static_assert(kMinValue < kMaxValue, "min value must be less than max value"); | 48 static_assert(kMinValue < kMaxValue, "min value must be less than max value"); |
49 | 49 |
50 private: | 50 private: |
51 // Declaration needed by Iterator. | 51 // Declaration needed by Iterator. |
52 typedef std::bitset<kValueCount> EnumBitSet; | 52 using EnumBitSet = std::bitset<kValueCount>; |
53 | 53 |
54 public: | 54 public: |
55 // Iterator is a forward-only read-only iterator for EnumSet. Its | 55 // Iterator is a forward-only read-only iterator for EnumSet. Its |
56 // interface is deliberately distinct from an STL iterator as its | 56 // interface is deliberately distinct from an STL iterator as its |
57 // semantics are substantially different. | 57 // semantics are substantially different. |
58 // | 58 // |
59 // Example usage: | 59 // Example usage: |
60 // | 60 // |
61 // for (EnumSet<...>::Iterator it = enums.First(); it.Good(); it.Inc()) { | 61 // for (EnumSet<...>::Iterator it = enums.First(); it.Good(); it.Inc()) { |
62 // Process(it.Get()); | 62 // Process(it.Get()); |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
254 | 254 |
255 template <typename E, E Min, E Max> | 255 template <typename E, E Min, E Max> |
256 EnumSet<E, Min, Max> Difference(EnumSet<E, Min, Max> set1, | 256 EnumSet<E, Min, Max> Difference(EnumSet<E, Min, Max> set1, |
257 EnumSet<E, Min, Max> set2) { | 257 EnumSet<E, Min, Max> set2) { |
258 return EnumSet<E, Min, Max>(set1.enums_ & ~set2.enums_); | 258 return EnumSet<E, Min, Max>(set1.enums_ & ~set2.enums_); |
259 } | 259 } |
260 | 260 |
261 } // namespace syncer | 261 } // namespace syncer |
262 | 262 |
263 #endif // COMPONENTS_SYNC_BASE_ENUM_SET_H_ | 263 #endif // COMPONENTS_SYNC_BASE_ENUM_SET_H_ |
OLD | NEW |