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 3 // found in the LICENSE file. 4 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 7 8 #include <map> 9 #include <unordered_map> 10 #include <utility> 11 12 namespace mojo { 13 14 // TODO(yzshen): These conversion functions should be removed and callsites 15 // should be revisited and changed to use the same map type. 16 template <typename Key, typename Value> 17 std::unordered_map<Key, Value> MapToUnorderedMap( 18 const std::map<Key, Value>& input) { 19 return std::unordered_map<Key, Value>(input.begin(), input.end()); 20 } 21 22 template <typename Key, typename Value> 23 std::unordered_map<Key, Value> MapToUnorderedMap(std::map<Key, Value>&& input) { 24 return std::unordered_map<Key, Value>(std::make_move_iterator(input.begin()), 25 std::make_move_iterator(input.end())); 26 } 27 28 template <typename Key, typename Value> 29 std::map<Key, Value> UnorderedMapToMap( 30 const std::unordered_map<Key, Value>& input) { 31 return std::map<Key, Value>(input.begin(), input.end()); 32 } 33 34 template <typename Key, typename Value> 35 std::map<Key, Value> UnorderedMapToMap(std::unordered_map<Key, Value>&& input) { 36 return std::map<Key, Value>(std::make_move_iterator(input.begin()), 37 std::make_move_iterator(input.end())); 38 } 39 40 } // namespace mojo 41 42 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_ 43