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 <utility>
10
11 #include "base/containers/flat_map.h"
12
13 namespace mojo {
14
15 // TODO(yzshen): These conversion functions should be removed and callsites
16 // should be revisited and changed to use the same map type.
17 template <typename Key, typename Value>
MapToFlatMap(const std::map<Key,Value> & input)18 base::flat_map<Key, Value> MapToFlatMap(const std::map<Key, Value>& input) {
19 return base::flat_map<Key, Value>(input.begin(), input.end());
20 }
21
22 template <typename Key, typename Value>
MapToFlatMap(std::map<Key,Value> && input)23 base::flat_map<Key, Value> MapToFlatMap(std::map<Key, Value>&& input) {
24 return base::flat_map<Key, Value>(std::make_move_iterator(input.begin()),
25 std::make_move_iterator(input.end()));
26 }
27
28 template <typename Key, typename Value>
FlatMapToMap(const base::flat_map<Key,Value> & input)29 std::map<Key, Value> FlatMapToMap(const base::flat_map<Key, Value>& input) {
30 return std::map<Key, Value>(input.begin(), input.end());
31 }
32
33 template <typename Key, typename Value>
FlatMapToMap(base::flat_map<Key,Value> && input)34 std::map<Key, Value> FlatMapToMap(base::flat_map<Key, Value>&& input) {
35 return std::map<Key, Value>(std::make_move_iterator(input.begin()),
36 std::make_move_iterator(input.end()));
37 }
38
39 } // namespace mojo
40
41 #endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
42