OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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_TRAITS_STL_H_ | 5 #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_ |
6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_ | 6 #define MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_ |
7 | 7 |
8 #include <map> | 8 #include <map> |
9 #include <unordered_map> | 9 #include <unordered_map> |
10 | 10 |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
87 | 87 |
88 static void AdvanceIterator(ConstIterator& iterator) { iterator++; } | 88 static void AdvanceIterator(ConstIterator& iterator) { iterator++; } |
89 static void AdvanceIterator(Iterator& iterator) { iterator++; } | 89 static void AdvanceIterator(Iterator& iterator) { iterator++; } |
90 | 90 |
91 static const K& GetKey(Iterator& iterator) { return iterator->first; } | 91 static const K& GetKey(Iterator& iterator) { return iterator->first; } |
92 static const K& GetKey(ConstIterator& iterator) { return iterator->first; } | 92 static const K& GetKey(ConstIterator& iterator) { return iterator->first; } |
93 | 93 |
94 static V& GetValue(Iterator& iterator) { return iterator->second; } | 94 static V& GetValue(Iterator& iterator) { return iterator->second; } |
95 static const V& GetValue(ConstIterator& iterator) { return iterator->second; } | 95 static const V& GetValue(ConstIterator& iterator) { return iterator->second; } |
96 | 96 |
97 static bool Insert(std::unordered_map<K, V>& input, const K& key, V&& value) { | 97 template <typename IK, typename IV> |
98 input.insert(std::make_pair(key, std::forward<V>(value))); | 98 static bool Insert(std::unordered_map<K, V>& input, IK&& key, IV&& value) { |
99 return true; | 99 input.insert( |
100 } | 100 std::make_pair(std::forward<IK>(key), std::forward<IV>(value))); |
101 static bool Insert(std::unordered_map<K, V>& input, | |
102 const K& key, | |
103 const V& value) { | |
104 input.insert(std::make_pair(key, value)); | |
105 return true; | 101 return true; |
106 } | 102 } |
107 | 103 |
108 static void SetToEmpty(std::unordered_map<K, V>* output) { output->clear(); } | 104 static void SetToEmpty(std::unordered_map<K, V>* output) { output->clear(); } |
109 }; | 105 }; |
110 | 106 |
111 } // namespace mojo | 107 } // namespace mojo |
112 | 108 |
113 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_ | 109 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_TRAITS_STL_H_ |
OLD | NEW |