| 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 MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| 7 | 7 |
| 8 #include <stddef.h> | 8 #include <stddef.h> |
| 9 #include <map> | 9 #include <map> |
| 10 #include <unordered_map> | 10 #include <unordered_map> |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 for (auto it = input.begin(); it != input.end(); ++it) { | 292 for (auto it = input.begin(); it != input.end(); ++it) { |
| 293 result.insert(std::make_pair( | 293 result.insert(std::make_pair( |
| 294 TypeConverter<STLKey, MojoKey>::Convert(it->first), | 294 TypeConverter<STLKey, MojoKey>::Convert(it->first), |
| 295 TypeConverter<STLValue, MojoValue>::Convert(it->second))); | 295 TypeConverter<STLValue, MojoValue>::Convert(it->second))); |
| 296 } | 296 } |
| 297 } | 297 } |
| 298 return result; | 298 return result; |
| 299 } | 299 } |
| 300 }; | 300 }; |
| 301 | 301 |
| 302 // TODO(yzshen): These conversion functions should be removed and callsites |
| 303 // should be revisited and changed to use the same map type. |
| 304 template <typename Key, typename Value> |
| 305 std::unordered_map<Key, Value> MapToUnorderedMap( |
| 306 const std::map<Key, Value>& input) { |
| 307 return std::unordered_map<Key, Value>(input.begin(), input.end()); |
| 308 } |
| 309 |
| 310 template <typename Key, typename Value> |
| 311 std::unordered_map<Key, Value> MapToUnorderedMap(std::map<Key, Value>&& input) { |
| 312 return std::unordered_map<Key, Value>(std::make_move_iterator(input.begin()), |
| 313 std::make_move_iterator(input.end())); |
| 314 } |
| 315 |
| 316 template <typename Key, typename Value> |
| 317 std::map<Key, Value> UnorderedMapToMap( |
| 318 const std::unordered_map<Key, Value>& input) { |
| 319 return std::map<Key, Value>(input.begin(), input.end()); |
| 320 } |
| 321 |
| 322 template <typename Key, typename Value> |
| 323 std::map<Key, Value> UnorderedMapToMap(std::unordered_map<Key, Value>&& input) { |
| 324 return std::map<Key, Value>(std::make_move_iterator(input.begin()), |
| 325 std::make_move_iterator(input.end())); |
| 326 } |
| 327 |
| 302 } // namespace mojo | 328 } // namespace mojo |
| 303 | 329 |
| 304 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ | 330 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ |
| OLD | NEW |