@@ -114,7 +114,8 @@ class map
114
114
{
115
115
auto operator ()(const value_t & v) { return Hash{}(v.first ); }
116
116
117
- auto operator ()(const K& v) { return Hash{}(v); }
117
+ template <typename Key>
118
+ auto operator ()(const Key& v) { return Hash{}(v); }
118
119
};
119
120
120
121
struct equal_key
@@ -124,7 +125,8 @@ class map
124
125
return Equal{}(a.first , b.first );
125
126
}
126
127
127
- auto operator ()(const value_t & a, const K& b)
128
+ template <typename Key>
129
+ auto operator ()(const value_t & a, const Key& b)
128
130
{
129
131
return Equal{}(a.first , b);
130
132
}
@@ -192,6 +194,21 @@ class map
192
194
*/
193
195
IMMER_NODISCARD bool empty () const { return impl_.size == 0 ; }
194
196
197
+ /* !
198
+ * Returns `1` when the key `k` is contained in the map or `0`
199
+ * otherwise. It won't allocate memory and its complexity is
200
+ * *effectively* @f$ O(1) @f$.
201
+ *
202
+ * This overload participates in overload resolution only if
203
+ * `Hash::is_transparent` is valid and denotes a type.
204
+ */
205
+ template <typename Key, typename U = Hash, typename = typename U::is_transparent>
206
+ IMMER_NODISCARD size_type count (const Key& k) const
207
+ {
208
+ return impl_.template get <detail::constantly<size_type, 1 >,
209
+ detail::constantly<size_type, 0 >>(k);
210
+ }
211
+
195
212
/* !
196
213
* Returns `1` when the key `k` is contained in the map or `0`
197
214
* otherwise. It won't allocate memory and its complexity is
@@ -203,6 +220,21 @@ class map
203
220
detail::constantly<size_type, 0 >>(k);
204
221
}
205
222
223
+ /* !
224
+ * Returns a `const` reference to the values associated to the key
225
+ * `k`. If the key is not contained in the map, it returns a
226
+ * default constructed value. It does not allocate memory and its
227
+ * complexity is *effectively* @f$ O(1) @f$.
228
+ *
229
+ * This overload participates in overload resolution only if
230
+ * `Hash::is_transparent` is valid and denotes a type.
231
+ */
232
+ template <typename Key, typename U = Hash, typename = typename U::is_transparent>
233
+ IMMER_NODISCARD const T& operator [](const Key& k) const
234
+ {
235
+ return impl_.template get <project_value, default_value>(k);
236
+ }
237
+
206
238
/* !
207
239
* Returns a `const` reference to the values associated to the key
208
240
* `k`. If the key is not contained in the map, it returns a
@@ -220,6 +252,21 @@ class map
220
252
* `std::out_of_range` error. It does not allocate memory and its
221
253
* complexity is *effectively* @f$ O(1) @f$.
222
254
*/
255
+ template <typename Key, typename U = Hash, typename = typename U::is_transparent>
256
+ const T& at (const Key& k) const
257
+ {
258
+ return impl_.template get <project_value, error_value>(k);
259
+ }
260
+
261
+ /* !
262
+ * Returns a `const` reference to the values associated to the key
263
+ * `k`. If the key is not contained in the map, throws an
264
+ * `std::out_of_range` error. It does not allocate memory and its
265
+ * complexity is *effectively* @f$ O(1) @f$.
266
+ *
267
+ * This overload participates in overload resolution only if
268
+ * `Hash::is_transparent` is valid and denotes a type.
269
+ */
223
270
const T& at (const K& k) const
224
271
{
225
272
return impl_.template get <project_value, error_value>(k);
@@ -260,6 +307,23 @@ class map
260
307
detail::constantly<const T*, nullptr >>(k);
261
308
}
262
309
310
+
311
+ /* !
312
+ * Returns a pointer to the value associated with the key `k`. If
313
+ * the key is not contained in the map, a `nullptr` is returned.
314
+ * It does not allocate memory and its complexity is *effectively*
315
+ * @f$ O(1) @f$.
316
+ *
317
+ * This overload participates in overload resolution only if
318
+ * `Hash::is_transparent` is valid and denotes a type.
319
+ */
320
+ template <typename Key, typename U = Hash, typename = typename U::is_transparent>
321
+ IMMER_NODISCARD const T* find (const Key& k) const
322
+ {
323
+ return impl_.template get <project_value_ptr,
324
+ detail::constantly<const T*, nullptr >>(k);
325
+ }
326
+
263
327
/* !
264
328
* Returns whether the sets are equal.
265
329
*/
0 commit comments