/src/abseil-cpp/absl/container/internal/raw_hash_map.h
Line  | Count  | Source  | 
1  |  | // Copyright 2018 The Abseil Authors.  | 
2  |  | //  | 
3  |  | // Licensed under the Apache License, Version 2.0 (the "License");  | 
4  |  | // you may not use this file except in compliance with the License.  | 
5  |  | // You may obtain a copy of the License at  | 
6  |  | //  | 
7  |  | //      https://www.apache.org/licenses/LICENSE-2.0  | 
8  |  | //  | 
9  |  | // Unless required by applicable law or agreed to in writing, software  | 
10  |  | // distributed under the License is distributed on an "AS IS" BASIS,  | 
11  |  | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  | 
12  |  | // See the License for the specific language governing permissions and  | 
13  |  | // limitations under the License.  | 
14  |  |  | 
15  |  | #ifndef ABSL_CONTAINER_INTERNAL_RAW_HASH_MAP_H_  | 
16  |  | #define ABSL_CONTAINER_INTERNAL_RAW_HASH_MAP_H_  | 
17  |  |  | 
18  |  | #include <tuple>  | 
19  |  | #include <type_traits>  | 
20  |  | #include <utility>  | 
21  |  |  | 
22  |  | #include "absl/base/attributes.h"  | 
23  |  | #include "absl/base/config.h"  | 
24  |  | #include "absl/base/internal/throw_delegate.h"  | 
25  |  | #include "absl/container/internal/common_policy_traits.h"  | 
26  |  | #include "absl/container/internal/container_memory.h"  | 
27  |  | #include "absl/container/internal/raw_hash_set.h"  // IWYU pragma: export  | 
28  |  | #include "absl/meta/type_traits.h"  | 
29  |  |  | 
30  |  | namespace absl { | 
31  |  | ABSL_NAMESPACE_BEGIN  | 
32  |  | namespace container_internal { | 
33  |  |  | 
34  |  | template <class Policy, class Hash, class Eq, class Alloc>  | 
35  |  | class raw_hash_map : public raw_hash_set<Policy, Hash, Eq, Alloc> { | 
36  |  |   // P is Policy. It's passed as a template argument to support maps that have  | 
37  |  |   // incomplete types as values, as in unordered_map<K, IncompleteType>.  | 
38  |  |   // MappedReference<> may be a non-reference type.  | 
39  |  |   template <class P>  | 
40  |  |   using MappedReference = decltype(P::value(  | 
41  |  |       std::addressof(std::declval<typename raw_hash_map::reference>())));  | 
42  |  |  | 
43  |  |   // MappedConstReference<> may be a non-reference type.  | 
44  |  |   template <class P>  | 
45  |  |   using MappedConstReference = decltype(P::value(  | 
46  |  |       std::addressof(std::declval<typename raw_hash_map::const_reference>())));  | 
47  |  |  | 
48  |  |   template <class K>  | 
49  |  |   using key_arg =  | 
50  |  |       typename KeyArg<IsTransparent<Eq>::value && IsTransparent<Hash>::value>::  | 
51  |  |           template type<K, typename Policy::key_type>;  | 
52  |  |  | 
53  |  |   // NOTE: The mess here is to shorten the code for the (very repetitive)  | 
54  |  |   // function overloads, and to allow the lifetime-bound overloads to dispatch  | 
55  |  |   // to the non-lifetime-bound overloads, to ensure there is a single source of  | 
56  |  |   // truth for each overload set.  | 
57  |  |   //  | 
58  |  |   // Enabled if an assignment from the given type would require the  | 
59  |  |   // source object to remain alive for the life of the element.  | 
60  |  |   //  | 
61  |  |   // TODO(b/402804213): Remove these traits and simplify the overloads whenever  | 
62  |  |   // we have a better mechanism available to handle lifetime analysis.  | 
63  |  |   template <class K, bool Value, typename = void>  | 
64  |  |   using LifetimeBoundK = HasValue<  | 
65  |  |       Value, std::conditional_t<policy_trait_element_is_owner<Policy>::value,  | 
66  |  |                                 std::false_type,  | 
67  |  |                                 type_traits_internal::IsLifetimeBoundAssignment<  | 
68  |  |                                     typename Policy::key_type, K>>>;  | 
69  |  |   template <class V, bool Value, typename = void>  | 
70  |  |   using LifetimeBoundV =  | 
71  |  |       HasValue<Value, type_traits_internal::IsLifetimeBoundAssignment<  | 
72  |  |                           typename Policy::mapped_type, V>>;  | 
73  |  |   template <class K, bool KValue, class V, bool VValue, typename... Dummy>  | 
74  |  |   using LifetimeBoundKV =  | 
75  |  |       absl::conjunction<LifetimeBoundK<K, KValue, absl::void_t<Dummy...>>,  | 
76  |  |                         LifetimeBoundV<V, VValue>>;  | 
77  |  |  | 
78  |  |  public:  | 
79  |  |   using key_type = typename Policy::key_type;  | 
80  |  |   using mapped_type = typename Policy::mapped_type;  | 
81  |  |  | 
82  |  |   static_assert(!std::is_reference<key_type>::value, "");  | 
83  |  |  | 
84  |  |   // TODO(b/187807849): Evaluate whether to support reference mapped_type and  | 
85  |  |   // remove this assertion if/when it is supported.  | 
86  |  |   static_assert(!std::is_reference<mapped_type>::value, "");  | 
87  |  |  | 
88  |  |   using iterator = typename raw_hash_map::raw_hash_set::iterator;  | 
89  |  |   using const_iterator = typename raw_hash_map::raw_hash_set::const_iterator;  | 
90  |  |  | 
91  | 2  |   raw_hash_map() {} | 
92  |  |   using raw_hash_map::raw_hash_set::raw_hash_set;  | 
93  |  |  | 
94  |  |   // The last two template parameters ensure that both arguments are rvalues  | 
95  |  |   // (lvalue arguments are handled by the overloads below). This is necessary  | 
96  |  |   // for supporting bitfield arguments.  | 
97  |  |   //  | 
98  |  |   //   union { int n : 1; }; | 
99  |  |   //   flat_hash_map<int, int> m;  | 
100  |  |   //   m.insert_or_assign(n, n);  | 
101  |  |   //  | 
102  |  |   // TODO(b/402804213): Remove these macros whenever we have a better mechanism  | 
103  |  |   // available to handle lifetime analysis.  | 
104  |  | #define ABSL_INTERNAL_X(Func, Callee, KQual, VQual, KValue, VValue, Tail, ...) \  | 
105  |  |   template <                                                                   \  | 
106  |  |       typename K = key_type, class V = mapped_type,                            \  | 
107  |  |       ABSL_INTERNAL_IF_##KValue##_NOR_##VValue(                                \  | 
108  |  |           int = (EnableIf<LifetimeBoundKV<K, KValue, V, VValue,                \  | 
109  |  |                                           IfRRef<int KQual>::AddPtr<K>,        \  | 
110  |  |                                           IfRRef<int VQual>::AddPtr<V>>>()),   \  | 
111  |  |           ABSL_INTERNAL_SINGLE_ARG(                                            \  | 
112  |  |               int &...,                                                        \  | 
113  |  |               decltype(EnableIf<LifetimeBoundKV<K, KValue, V, VValue>>()) =    \  | 
114  |  |                   0))>                                                         \  | 
115  |  |   decltype(auto) Func(                                                         \  | 
116  |  |       __VA_ARGS__ key_arg<K> KQual k ABSL_INTERNAL_IF_##KValue(                \  | 
117  |  |           ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this)),                          \  | 
118  |  |       V VQual v ABSL_INTERNAL_IF_##VValue(ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY( \  | 
119  |  |           this))) ABSL_ATTRIBUTE_LIFETIME_BOUND {                              \ | 
120  |  |     return ABSL_INTERNAL_IF_##KValue##_OR_##VValue(                            \  | 
121  |  |         (this->template Func<K, V, 0>), Callee)(                               \  | 
122  |  |         std::forward<decltype(k)>(k), std::forward<decltype(v)>(v)) Tail;      \  | 
123  |  |   }                                                                            \  | 
124  |  |   static_assert(true, "This is to force a semicolon.")  | 
125  |  |  | 
126  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
127  |  |                   false, false, ABSL_INTERNAL_SINGLE_ARG());  | 
128  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
129  |  |                   false, true, ABSL_INTERNAL_SINGLE_ARG());  | 
130  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
131  |  |                   true, false, ABSL_INTERNAL_SINGLE_ARG());  | 
132  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
133  |  |                   true, true, ABSL_INTERNAL_SINGLE_ARG());  | 
134  |  |  | 
135  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, false,  | 
136  |  |                   false, ABSL_INTERNAL_SINGLE_ARG());  | 
137  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, false,  | 
138  |  |                   true, ABSL_INTERNAL_SINGLE_ARG());  | 
139  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, true,  | 
140  |  |                   false, ABSL_INTERNAL_SINGLE_ARG());  | 
141  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, true,  | 
142  |  |                   true, ABSL_INTERNAL_SINGLE_ARG());  | 
143  |  |  | 
144  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, false,  | 
145  |  |                   false, ABSL_INTERNAL_SINGLE_ARG());  | 
146  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, false,  | 
147  |  |                   true, ABSL_INTERNAL_SINGLE_ARG());  | 
148  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, true,  | 
149  |  |                   false, ABSL_INTERNAL_SINGLE_ARG());  | 
150  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, true,  | 
151  |  |                   true, ABSL_INTERNAL_SINGLE_ARG());  | 
152  |  |  | 
153  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, false, false,  | 
154  |  |                   ABSL_INTERNAL_SINGLE_ARG());  | 
155  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, false, true,  | 
156  |  |                   ABSL_INTERNAL_SINGLE_ARG());  | 
157  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, true, false,  | 
158  |  |                   ABSL_INTERNAL_SINGLE_ARG());  | 
159  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, true, true,  | 
160  |  |                   ABSL_INTERNAL_SINGLE_ARG());  | 
161  |  |  | 
162  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
163  |  |                   false, false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
164  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
165  |  |                   false, true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
166  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
167  |  |                   true, false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
168  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, const &,  | 
169  |  |                   true, true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
170  |  |  | 
171  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, false,  | 
172  |  |                   false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
173  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, false,  | 
174  |  |                   true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
175  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, true,  | 
176  |  |                   false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
177  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, const &, &&, true,  | 
178  |  |                   true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
179  |  |  | 
180  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, false,  | 
181  |  |                   false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
182  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, false,  | 
183  |  |                   true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
184  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, true,  | 
185  |  |                   false, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
186  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, const &, true,  | 
187  |  |                   true, .first, const_iterator ABSL_INTERNAL_COMMA);  | 
188  |  |  | 
189  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, false, false,  | 
190  |  |                   .first, const_iterator ABSL_INTERNAL_COMMA);  | 
191  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, false, true,  | 
192  |  |                   .first, const_iterator ABSL_INTERNAL_COMMA);  | 
193  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, true, false,  | 
194  |  |                   .first, const_iterator ABSL_INTERNAL_COMMA);  | 
195  |  |   ABSL_INTERNAL_X(insert_or_assign, insert_or_assign_impl, &&, &&, true, true,  | 
196  |  |                   .first, const_iterator ABSL_INTERNAL_COMMA);  | 
197  |  | #undef ABSL_INTERNAL_X  | 
198  |  |  | 
199  |  |   // All `try_emplace()` overloads make the same guarantees regarding rvalue  | 
200  |  |   // arguments as `std::unordered_map::try_emplace()`, namely that these  | 
201  |  |   // functions will not move from rvalue arguments if insertions do not happen.  | 
202  |  |   template <class K = key_type, int = EnableIf<LifetimeBoundK<K, false, K *>>(),  | 
203  |  |             class... Args,  | 
204  |  |             typename std::enable_if<  | 
205  |  |                 !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
206  |  |   std::pair<iterator, bool> try_emplace(key_arg<K> &&k, Args &&...args)  | 
207  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
208  |  |     return try_emplace_impl(std::forward<key_arg<K>>(k),  | 
209  |  |                             std::forward<Args>(args)...);  | 
210  |  |   }  | 
211  |  |  | 
212  |  |   template <class K = key_type, class... Args,  | 
213  |  |             EnableIf<LifetimeBoundK<K, true, K *>> = 0,  | 
214  |  |             typename std::enable_if<  | 
215  |  |                 !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
216  |  |   std::pair<iterator, bool> try_emplace(  | 
217  |  |       key_arg<K> &&k ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this),  | 
218  |  |       Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
219  |  |     return this->template try_emplace<K, 0>(std::forward<key_arg<K>>(k),  | 
220  |  |                                             std::forward<Args>(args)...);  | 
221  |  |   }  | 
222  |  |  | 
223  |  |   template <class K = key_type, int = EnableIf<LifetimeBoundK<K, false>>(),  | 
224  |  |             class... Args,  | 
225  |  |             typename std::enable_if<  | 
226  |  |                 !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
227  |  |   std::pair<iterator, bool> try_emplace(const key_arg<K> &k, Args &&...args)  | 
228  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
229  |  |     return try_emplace_impl(k, std::forward<Args>(args)...);  | 
230  |  |   }  | 
231  |  |   template <class K = key_type, class... Args,  | 
232  |  |             EnableIf<LifetimeBoundK<K, true>> = 0,  | 
233  |  |             typename std::enable_if<  | 
234  |  |                 !std::is_convertible<K, const_iterator>::value, int>::type = 0>  | 
235  |  |   std::pair<iterator, bool> try_emplace(  | 
236  |  |       const key_arg<K> &k ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this),  | 
237  |  |       Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
238  |  |     return this->template try_emplace<K, 0>(k, std::forward<Args>(args)...);  | 
239  |  |   }  | 
240  |  |  | 
241  |  |   template <class K = key_type, int = EnableIf<LifetimeBoundK<K, false, K *>>(),  | 
242  |  |             class... Args>  | 
243  |  |   iterator try_emplace(const_iterator, key_arg<K> &&k,  | 
244  |  |                        Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
245  |  |     return try_emplace(std::forward<key_arg<K>>(k), std::forward<Args>(args)...)  | 
246  |  |         .first;  | 
247  |  |   }  | 
248  |  |   template <class K = key_type, class... Args,  | 
249  |  |             EnableIf<LifetimeBoundK<K, true, K *>> = 0>  | 
250  |  |   iterator try_emplace(const_iterator hint,  | 
251  |  |                        key_arg<K> &&k ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this),  | 
252  |  |                        Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
253  |  |     return this->template try_emplace<K, 0>(hint, std::forward<key_arg<K>>(k),  | 
254  |  |                                             std::forward<Args>(args)...);  | 
255  |  |   }  | 
256  |  |  | 
257  |  |   template <class K = key_type, int = EnableIf<LifetimeBoundK<K, false>>(),  | 
258  |  |             class... Args>  | 
259  |  |   iterator try_emplace(const_iterator, const key_arg<K> &k,  | 
260  |  |                        Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
261  |  |     return try_emplace(k, std::forward<Args>(args)...).first;  | 
262  |  |   }  | 
263  |  |   template <class K = key_type, class... Args,  | 
264  |  |             EnableIf<LifetimeBoundK<K, true>> = 0>  | 
265  |  |   iterator try_emplace(const_iterator hint,  | 
266  |  |                        const key_arg<K> &k  | 
267  |  |                            ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this),  | 
268  |  |                        Args &&...args) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
269  |  |     return this->template try_emplace<K, 0>(hint, k,  | 
270  |  |                                             std::forward<Args>(args)...);  | 
271  |  |   }  | 
272  |  |  | 
273  |  |   template <class K = key_type, class P = Policy>  | 
274  |  |   MappedReference<P> at(const key_arg<K>& key) ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
275  |  |     auto it = this->find(key);  | 
276  |  |     if (it == this->end()) { | 
277  |  |       base_internal::ThrowStdOutOfRange(  | 
278  |  |           "absl::container_internal::raw_hash_map<>::at");  | 
279  |  |     }  | 
280  |  |     return Policy::value(&*it);  | 
281  |  |   }  | 
282  |  |  | 
283  |  |   template <class K = key_type, class P = Policy>  | 
284  |  |   MappedConstReference<P> at(const key_arg<K>& key) const  | 
285  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
286  |  |     auto it = this->find(key);  | 
287  |  |     if (it == this->end()) { | 
288  |  |       base_internal::ThrowStdOutOfRange(  | 
289  |  |           "absl::container_internal::raw_hash_map<>::at");  | 
290  |  |     }  | 
291  |  |     return Policy::value(&*it);  | 
292  |  |   }  | 
293  |  |  | 
294  |  |   template <class K = key_type, class P = Policy,  | 
295  |  |             int = EnableIf<LifetimeBoundK<K, false, K *>>()>  | 
296  |  |   MappedReference<P> operator[](key_arg<K> &&key)  | 
297  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
298  |  |     // It is safe to use unchecked_deref here because try_emplace  | 
299  |  |     // will always return an iterator pointing to a valid item in the table,  | 
300  |  |     // since it inserts if nothing is found for the given key.  | 
301  |  |     return Policy::value(&this->unchecked_deref(  | 
302  |  |         try_emplace(std::forward<key_arg<K>>(key)).first));  | 
303  |  |   }  | 
304  |  |   template <class K = key_type, class P = Policy, int &...,  | 
305  |  |             EnableIf<LifetimeBoundK<K, true, K *>> = 0>  | 
306  |  |   MappedReference<P> operator[](  | 
307  |  |       key_arg<K> &&key ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this))  | 
308  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
309  |  |     return this->template operator[]<K, P, 0>(std::forward<key_arg<K>>(key));  | 
310  |  |   }  | 
311  |  |  | 
312  |  |   template <class K = key_type, class P = Policy,  | 
313  |  |             int = EnableIf<LifetimeBoundK<K, false>>()>  | 
314  |  |   MappedReference<P> operator[](const key_arg<K> &key)  | 
315  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
316  |  |     // It is safe to use unchecked_deref here because try_emplace  | 
317  |  |     // will always return an iterator pointing to a valid item in the table,  | 
318  |  |     // since it inserts if nothing is found for the given key.  | 
319  |  |     return Policy::value(&this->unchecked_deref(try_emplace(key).first));  | 
320  |  |   }  | 
321  |  |   template <class K = key_type, class P = Policy, int &...,  | 
322  |  |             EnableIf<LifetimeBoundK<K, true>> = 0>  | 
323  |  |   MappedReference<P> operator[](  | 
324  |  |       const key_arg<K> &key ABSL_INTERNAL_ATTRIBUTE_CAPTURED_BY(this))  | 
325  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
326  |  |     return this->template operator[]<K, P, 0>(key);  | 
327  |  |   }  | 
328  |  |  | 
329  |  |  private:  | 
330  |  |   template <class K, class V>  | 
331  |  |   std::pair<iterator, bool> insert_or_assign_impl(K&& k, V&& v)  | 
332  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
333  |  |     auto res = this->find_or_prepare_insert(k);  | 
334  |  |     if (res.second) { | 
335  |  |       this->emplace_at(res.first, std::forward<K>(k), std::forward<V>(v));  | 
336  |  |     } else { | 
337  |  |       Policy::value(&*res.first) = std::forward<V>(v);  | 
338  |  |     }  | 
339  |  |     return res;  | 
340  |  |   }  | 
341  |  |  | 
342  |  |   template <class K = key_type, class... Args>  | 
343  |  |   std::pair<iterator, bool> try_emplace_impl(K&& k, Args&&... args)  | 
344  |  |       ABSL_ATTRIBUTE_LIFETIME_BOUND { | 
345  |  |     auto res = this->find_or_prepare_insert(k);  | 
346  |  |     if (res.second) { | 
347  |  |       this->emplace_at(res.first, std::piecewise_construct,  | 
348  |  |                        std::forward_as_tuple(std::forward<K>(k)),  | 
349  |  |                        std::forward_as_tuple(std::forward<Args>(args)...));  | 
350  |  |     }  | 
351  |  |     return res;  | 
352  |  |   }  | 
353  |  | };  | 
354  |  |  | 
355  |  | }  // namespace container_internal  | 
356  |  | ABSL_NAMESPACE_END  | 
357  |  | }  // namespace absl  | 
358  |  |  | 
359  |  | #endif  // ABSL_CONTAINER_INTERNAL_RAW_HASH_MAP_H_  |