| OLD | NEW |
| (Empty) |
| 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_LIB_MAP_INTERNAL_H_ | |
| 6 #define MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ | |
| 7 | |
| 8 #include <map> | |
| 9 | |
| 10 #include "mojo/public/cpp/bindings/array.h" | |
| 11 #include "mojo/public/cpp/bindings/lib/template_util.h" | |
| 12 | |
| 13 namespace mojo { | |
| 14 namespace internal { | |
| 15 | |
| 16 template <typename Key, typename Value, bool kValueIsMoveOnlyType> | |
| 17 struct MapTraits {}; | |
| 18 | |
| 19 // Defines traits of a map for which Value is not a move-only type. | |
| 20 template <typename Key, typename Value> | |
| 21 struct MapTraits<Key, Value, false> { | |
| 22 typedef const Value& ValueForwardType; | |
| 23 | |
| 24 static inline void Insert(std::map<Key, Value>* m, | |
| 25 const Key& key, | |
| 26 ValueForwardType value) { | |
| 27 m->insert(std::make_pair(key, value)); | |
| 28 } | |
| 29 static inline void Clone(const std::map<Key, Value>& src, | |
| 30 std::map<Key, Value>* dst) { | |
| 31 dst->clear(); | |
| 32 for (auto it = src.begin(); it != src.end(); ++it) | |
| 33 dst->insert(*it); | |
| 34 } | |
| 35 }; | |
| 36 | |
| 37 // Defines traits of a map for which Value is a move-only type. | |
| 38 template <typename Key, typename Value> | |
| 39 struct MapTraits<Key, Value, true> { | |
| 40 typedef Value ValueForwardType; | |
| 41 | |
| 42 static inline void Insert(std::map<Key, Value>* m, | |
| 43 const Key& key, | |
| 44 Value& value) { | |
| 45 m->insert(std::make_pair(key, value.Pass())); | |
| 46 } | |
| 47 static inline void Clone(const std::map<Key, Value>& src, | |
| 48 std::map<Key, Value>* dst) { | |
| 49 dst->clear(); | |
| 50 for (auto it = src.begin(); it != src.end(); ++it) | |
| 51 dst->insert(std::make_pair(it->first, it->second.Clone())); | |
| 52 } | |
| 53 }; | |
| 54 | |
| 55 } // namespace internal | |
| 56 } // namespace mojo | |
| 57 | |
| 58 #endif // MOJO_PUBLIC_CPP_BINDINGS_LIB_MAP_INTERNAL_H_ | |
| OLD | NEW |