blob: 350bfad76ae71261303def9298a67235dc034f21 [file] [log] [blame]
rockot85dce0862015-11-13 01:33:591// 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
rockot85dce0862015-11-13 01:33:598#include <map>
dchengaa6492d2015-12-26 04:46:369#include <utility>
rockot85dce0862015-11-13 01:33:5910
Ken Rockot089427352018-04-24 14:51:3711#include "base/containers/flat_map.h"
12
rockot85dce0862015-11-13 01:33:5913namespace mojo {
14
yzshen6a5ee17d2016-11-21 17:43:2815// TODO(yzshen): These conversion functions should be removed and callsites
16// should be revisited and changed to use the same map type.
17template <typename Key, typename Value>
Ken Rockot089427352018-04-24 14:51:3718base::flat_map<Key, Value> MapToFlatMap(const std::map<Key, Value>& input) {
19 return base::flat_map<Key, Value>(input.begin(), input.end());
yzshen6a5ee17d2016-11-21 17:43:2820}
21
22template <typename Key, typename Value>
Ken Rockot089427352018-04-24 14:51:3723base::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()));
yzshen6a5ee17d2016-11-21 17:43:2826}
27
28template <typename Key, typename Value>
Ken Rockot089427352018-04-24 14:51:3729std::map<Key, Value> FlatMapToMap(const base::flat_map<Key, Value>& input) {
yzshen6a5ee17d2016-11-21 17:43:2830 return std::map<Key, Value>(input.begin(), input.end());
31}
32
33template <typename Key, typename Value>
Ken Rockot089427352018-04-24 14:51:3734std::map<Key, Value> FlatMapToMap(base::flat_map<Key, Value>&& input) {
yzshen6a5ee17d2016-11-21 17:43:2835 return std::map<Key, Value>(std::make_move_iterator(input.begin()),
36 std::make_move_iterator(input.end()));
37}
38
rockot85dce0862015-11-13 01:33:5939} // namespace mojo
40
41#endif // MOJO_PUBLIC_CPP_BINDINGS_MAP_H_