Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(254)

Side by Side Diff: components/sync/base/enum_set.h

Issue 2689773002: [Sync] Replace typedef with using. (Closed)
Patch Set: [Sync] Replace typedef with using. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/sync/base/cryptographer.h ('k') | components/sync/base/enum_set_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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_
OLDNEW
« no previous file with comments | « components/sync/base/cryptographer.h ('k') | components/sync/base/enum_set_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698