xref: /aosp_15_r20/external/libchrome/mojo/public/cpp/bindings/map.h (revision 635a864187cb8b6c713ff48b7e790a6b21769273)
1*635a8641SAndroid Build Coastguard Worker // Copyright 2014 The Chromium Authors. All rights reserved.
2*635a8641SAndroid Build Coastguard Worker // Use of this source code is governed by a BSD-style license that can be
3*635a8641SAndroid Build Coastguard Worker // found in the LICENSE file.
4*635a8641SAndroid Build Coastguard Worker 
5*635a8641SAndroid Build Coastguard Worker #ifndef MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
6*635a8641SAndroid Build Coastguard Worker #define MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
7*635a8641SAndroid Build Coastguard Worker 
8*635a8641SAndroid Build Coastguard Worker #include <map>
9*635a8641SAndroid Build Coastguard Worker #include <utility>
10*635a8641SAndroid Build Coastguard Worker 
11*635a8641SAndroid Build Coastguard Worker #include "base/containers/flat_map.h"
12*635a8641SAndroid Build Coastguard Worker 
13*635a8641SAndroid Build Coastguard Worker namespace mojo {
14*635a8641SAndroid Build Coastguard Worker 
15*635a8641SAndroid Build Coastguard Worker // TODO(yzshen): These conversion functions should be removed and callsites
16*635a8641SAndroid Build Coastguard Worker // should be revisited and changed to use the same map type.
17*635a8641SAndroid Build Coastguard Worker template <typename Key, typename Value>
MapToFlatMap(const std::map<Key,Value> & input)18*635a8641SAndroid Build Coastguard Worker base::flat_map<Key, Value> MapToFlatMap(const std::map<Key, Value>& input) {
19*635a8641SAndroid Build Coastguard Worker   return base::flat_map<Key, Value>(input.begin(), input.end());
20*635a8641SAndroid Build Coastguard Worker }
21*635a8641SAndroid Build Coastguard Worker 
22*635a8641SAndroid Build Coastguard Worker template <typename Key, typename Value>
MapToFlatMap(std::map<Key,Value> && input)23*635a8641SAndroid Build Coastguard Worker base::flat_map<Key, Value> MapToFlatMap(std::map<Key, Value>&& input) {
24*635a8641SAndroid Build Coastguard Worker   return base::flat_map<Key, Value>(std::make_move_iterator(input.begin()),
25*635a8641SAndroid Build Coastguard Worker                                     std::make_move_iterator(input.end()));
26*635a8641SAndroid Build Coastguard Worker }
27*635a8641SAndroid Build Coastguard Worker 
28*635a8641SAndroid Build Coastguard Worker template <typename Key, typename Value>
FlatMapToMap(const base::flat_map<Key,Value> & input)29*635a8641SAndroid Build Coastguard Worker std::map<Key, Value> FlatMapToMap(const base::flat_map<Key, Value>& input) {
30*635a8641SAndroid Build Coastguard Worker   return std::map<Key, Value>(input.begin(), input.end());
31*635a8641SAndroid Build Coastguard Worker }
32*635a8641SAndroid Build Coastguard Worker 
33*635a8641SAndroid Build Coastguard Worker template <typename Key, typename Value>
FlatMapToMap(base::flat_map<Key,Value> && input)34*635a8641SAndroid Build Coastguard Worker std::map<Key, Value> FlatMapToMap(base::flat_map<Key, Value>&& input) {
35*635a8641SAndroid Build Coastguard Worker   return std::map<Key, Value>(std::make_move_iterator(input.begin()),
36*635a8641SAndroid Build Coastguard Worker                               std::make_move_iterator(input.end()));
37*635a8641SAndroid Build Coastguard Worker }
38*635a8641SAndroid Build Coastguard Worker 
39*635a8641SAndroid Build Coastguard Worker }  // namespace mojo
40*635a8641SAndroid Build Coastguard Worker 
41*635a8641SAndroid Build Coastguard Worker #endif  // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_
42