1 | /* |
2 | * Copyright 2015-present Facebook, Inc. |
3 | * |
4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | * you may not use this file except in compliance with the License. |
6 | * You may obtain a copy of the License at |
7 | * |
8 | * http://www.apache.org/licenses/LICENSE-2.0 |
9 | * |
10 | * Unless required by applicable law or agreed to in writing, software |
11 | * distributed under the License is distributed on an "AS IS" BASIS, |
12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
13 | * See the License for the specific language governing permissions and |
14 | * limitations under the License. |
15 | */ |
16 | |
17 | #pragma once |
18 | |
19 | #include <folly/Range.h> |
20 | #include <folly/container/F14Map.h> |
21 | |
22 | namespace folly { |
23 | |
24 | template < |
25 | class Mapped, |
26 | class Hash = f14::DefaultHasher<std::string>, |
27 | class Eq = f14::DefaultKeyEqual<std::string>, |
28 | class Alloc = f14::DefaultAlloc<std::pair<std::string const, Mapped>>> |
29 | struct StringKeyedUnorderedMap |
30 | : public F14NodeMap<std::string, Mapped, Hash, Eq, Alloc> { |
31 | using Super = F14NodeMap<std::string, Mapped, Hash, Eq, Alloc>; |
32 | |
33 | using require_transparent_hash = typename Hash::is_transparent; |
34 | using require_transparent_eq = typename Eq::is_transparent; |
35 | |
36 | public: |
37 | using Super::Super; |
38 | StringKeyedUnorderedMap() : Super() {} |
39 | |
40 | // TODO(T31574848): Work around libstdc++ versions (e.g., GCC < 6) with no |
41 | // implementation of N4387 ("perfect initialization" for pairs and tuples) to |
42 | // support existing callsites that list-initialize: |
43 | // m.insert({sp, x}); |
44 | std::pair<typename Super::iterator, bool> insert( |
45 | std::pair<StringPiece, Mapped> const& p) { |
46 | return this->emplace(p.first, p.second); |
47 | } |
48 | std::pair<typename Super::iterator, bool> insert( |
49 | std::pair<StringPiece, Mapped>&& p) { |
50 | return this->emplace(std::move(p)); |
51 | } |
52 | }; |
53 | |
54 | } // namespace folly |
55 | |