OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 BASE_SCOPED_GENERIC_H_ | 5 #ifndef BASE_SCOPED_GENERIC_H_ |
6 #define BASE_SCOPED_GENERIC_H_ | 6 #define BASE_SCOPED_GENERIC_H_ |
7 | 7 |
8 #include <stdlib.h> | 8 #include <stdlib.h> |
9 | 9 |
10 #include <algorithm> | 10 #include <algorithm> |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 // | 46 // |
47 // // This free function will not be called if f == InvalidValue()! | 47 // // This free function will not be called if f == InvalidValue()! |
48 // static void Free(int f) { | 48 // static void Free(int f) { |
49 // ::FreeFoo(f); | 49 // ::FreeFoo(f); |
50 // } | 50 // } |
51 // }; | 51 // }; |
52 // | 52 // |
53 // typedef ScopedGeneric<int, FooScopedTraits> ScopedFoo; | 53 // typedef ScopedGeneric<int, FooScopedTraits> ScopedFoo; |
54 template<typename T, typename Traits> | 54 template<typename T, typename Traits> |
55 class ScopedGeneric { | 55 class ScopedGeneric { |
56 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedGeneric) | 56 DISALLOW_COPY_AND_ASSIGN_WITH_MOVE_FOR_BIND(ScopedGeneric) |
57 | 57 |
58 private: | 58 private: |
59 // This must be first since it's used inline below. | 59 // This must be first since it's used inline below. |
60 // | 60 // |
61 // Use the empty base class optimization to allow us to have a D | 61 // Use the empty base class optimization to allow us to have a D |
62 // member, while avoiding any space overhead for it when D is an | 62 // member, while avoiding any space overhead for it when D is an |
63 // empty class. See e.g. http://www.cantrip.org/emptyopt.html for a good | 63 // empty class. See e.g. http://www.cantrip.org/emptyopt.html for a good |
64 // discussion of this technique. | 64 // discussion of this technique. |
65 struct Data : public Traits { | 65 struct Data : public Traits { |
66 explicit Data(const T& in) : generic(in) {} | 66 explicit Data(const T& in) : generic(in) {} |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
173 } | 173 } |
174 | 174 |
175 template<class T, class Traits> | 175 template<class T, class Traits> |
176 bool operator!=(const T& value, const ScopedGeneric<T, Traits>& scoped) { | 176 bool operator!=(const T& value, const ScopedGeneric<T, Traits>& scoped) { |
177 return value != scoped.get(); | 177 return value != scoped.get(); |
178 } | 178 } |
179 | 179 |
180 } // namespace base | 180 } // namespace base |
181 | 181 |
182 #endif // BASE_SCOPED_GENERIC_H_ | 182 #endif // BASE_SCOPED_GENERIC_H_ |
OLD | NEW |