OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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_CONTAINERS_SCOPED_PTR_MAP_H_ | 5 #ifndef BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
6 #define BASE_CONTAINERS_SCOPED_PTR_MAP_H_ | 6 #define BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
7 | 7 |
8 #include <functional> | 8 #include <functional> |
9 #include <map> | 9 #include <map> |
10 #include <utility> | 10 #include <utility> |
11 | 11 |
12 #include "base/basictypes.h" | 12 #include "base/basictypes.h" |
13 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
14 #include "base/move.h" | 14 #include "base/move.h" |
15 #include "base/stl_util.h" | 15 #include "base/stl_util.h" |
16 | 16 |
| 17 namespace base { |
| 18 |
17 // ScopedPtrMap provides a std::map that supports scoped_ptr values. It ensures | 19 // ScopedPtrMap provides a std::map that supports scoped_ptr values. It ensures |
18 // that the map's values are properly deleted when removed from the map, or when | 20 // that the map's values are properly deleted when removed from the map, or when |
19 // the map is destroyed. | 21 // the map is destroyed. |
20 // | 22 // |
21 // |ScopedPtr| must be a type scoped_ptr<T>. This is for compatibility with | 23 // |ScopedPtr| must be a type scoped_ptr<T>. This is for compatibility with |
22 // std::map in C++11. | 24 // std::map in C++11. |
23 template <class Key, class ScopedPtr, class Compare = std::less<Key>> | 25 template <class Key, class ScopedPtr, class Compare = std::less<Key>> |
24 class ScopedPtrMap { | 26 class ScopedPtrMap { |
25 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPtrMap) | 27 MOVE_ONLY_TYPE_WITH_MOVE_CONSTRUCTOR_FOR_CPP_03(ScopedPtrMap) |
26 | 28 |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
130 | 132 |
131 typename Container::iterator ConstIteratorToIterator(const_iterator it) { | 133 typename Container::iterator ConstIteratorToIterator(const_iterator it) { |
132 // This is the only way to convert a const iterator to a non-const iterator | 134 // This is the only way to convert a const iterator to a non-const iterator |
133 // in C++03 (get the key and do the lookup again). | 135 // in C++03 (get the key and do the lookup again). |
134 if (it == data_.end()) | 136 if (it == data_.end()) |
135 return data_.end(); | 137 return data_.end(); |
136 return data_.find(it->first); | 138 return data_.find(it->first); |
137 }; | 139 }; |
138 }; | 140 }; |
139 | 141 |
| 142 } // namespace base |
| 143 |
140 #endif // BASE_CONTAINERS_SCOPED_PTR_MAP_H_ | 144 #endif // BASE_CONTAINERS_SCOPED_PTR_MAP_H_ |
OLD | NEW |