Coverage Report

Created: 2026-07-16 06:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/abseil-cpp/absl/container/internal/container_memory.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_CONTAINER_MEMORY_H_
16
#define ABSL_CONTAINER_INTERNAL_CONTAINER_MEMORY_H_
17
18
#include <cassert>
19
#include <cstddef>
20
#include <cstdint>
21
#include <cstring>
22
#include <memory>
23
#include <new>
24
#include <tuple>
25
#include <type_traits>
26
#include <utility>
27
28
#include "absl/base/config.h"
29
#include "absl/hash/hash.h"
30
#include "absl/memory/memory.h"
31
#include "absl/meta/type_traits.h"
32
#include "absl/utility/utility.h"
33
34
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
35
#include <sanitizer/asan_interface.h>
36
#endif
37
38
#ifdef ABSL_HAVE_MEMORY_SANITIZER
39
#include <sanitizer/msan_interface.h>
40
#endif
41
42
namespace absl {
43
ABSL_NAMESPACE_BEGIN
44
namespace container_internal {
45
46
template <size_t Alignment>
47
struct alignas(Alignment) AlignedType {
48
  // When alignment is sufficient for the allocated memory to store pointers,
49
  // include a pointer member so that swisstable backing arrays end up in the
50
  // pointer-containing partition for heap partitioning.
51
  std::conditional_t<(Alignment < alignof(void*)), char, void*> pointer;
52
};
53
54
// Allocates at least n bytes aligned to the specified alignment.
55
// Alignment must be a power of 2. It must be positive.
56
//
57
// Note that many allocators don't honor alignment requirements above certain
58
// threshold (usually either alignof(std::max_align_t) or alignof(void*)).
59
// Allocate() doesn't apply alignment corrections. If the underlying allocator
60
// returns insufficiently alignment pointer, that's what you are going to get.
61
template <size_t Alignment, class Alloc>
62
241k
void* Allocate(Alloc* alloc, size_t n) {
63
241k
  static_assert(Alignment > 0, "");
64
241k
  assert(n && "n must be positive");
65
241k
  using M = AlignedType<Alignment>;
66
241k
  using A = typename std::allocator_traits<Alloc>::template rebind_alloc<M>;
67
241k
  using AT = typename std::allocator_traits<Alloc>::template rebind_traits<M>;
68
  // On macOS, "mem_alloc" is a #define with one argument defined in
69
  // rpc/types.h, so we can't name the variable "mem_alloc" and initialize it
70
  // with the "foo(bar)" syntax.
71
241k
  A my_mem_alloc(*alloc);
72
241k
  void* p = AT::allocate(my_mem_alloc, (n + sizeof(M) - 1) / sizeof(M));
73
241k
  assert(reinterpret_cast<uintptr_t>(p) % Alignment == 0 &&
74
241k
         "allocator does not respect alignment");
75
241k
  return p;
76
241k
}
77
78
// Returns true if the destruction of the value with given Allocator will be
79
// trivial.
80
template <class Allocator, class ValueType>
81
constexpr auto IsDestructionTrivial() {
82
  constexpr bool result =
83
      std::is_trivially_destructible_v<ValueType> &&
84
      std::is_same_v<typename std::allocator_traits<
85
                         Allocator>::template rebind_alloc<char>,
86
                     std::allocator<char>>;
87
  return std::integral_constant<bool, result>();
88
}
89
90
// The pointer must have been previously obtained by calling
91
// Allocate<Alignment>(alloc, n).
92
template <size_t Alignment, class Alloc>
93
241k
void Deallocate(Alloc* alloc, void* p, size_t n) {
94
241k
  static_assert(Alignment > 0, "");
95
241k
  assert(n && "n must be positive");
96
241k
  using M = AlignedType<Alignment>;
97
241k
  using A = typename std::allocator_traits<Alloc>::template rebind_alloc<M>;
98
241k
  using AT = typename std::allocator_traits<Alloc>::template rebind_traits<M>;
99
  // On macOS, "mem_alloc" is a #define with one argument defined in
100
  // rpc/types.h, so we can't name the variable "mem_alloc" and initialize it
101
  // with the "foo(bar)" syntax.
102
241k
  A my_mem_alloc(*alloc);
103
241k
  AT::deallocate(my_mem_alloc, static_cast<M*>(p),
104
241k
                 (n + sizeof(M) - 1) / sizeof(M));
105
241k
}
106
107
namespace memory_internal {
108
109
// Constructs T into uninitialized storage pointed by `ptr` using the args
110
// specified in the tuple.
111
template <class Alloc, class T, class Tuple, size_t... I>
112
void ConstructFromTupleImpl(Alloc* alloc, T* ptr, Tuple&& t,
113
                            std::index_sequence<I...>) {
114
  std::allocator_traits<Alloc>::construct(
115
      *alloc, ptr, std::get<I>(std::forward<Tuple>(t))...);
116
}
117
118
template <class T, class F>
119
struct WithConstructedImplF {
120
  template <class... Args>
121
  decltype(std::declval<F>()(std::declval<T>())) operator()(
122
      Args&&... args) const {
123
    return std::forward<F>(f)(T(std::forward<Args>(args)...));
124
  }
125
  F&& f;
126
};
127
128
template <class T, class Tuple, size_t... Is, class F>
129
decltype(std::declval<F>()(std::declval<T>())) WithConstructedImpl(
130
    Tuple&& t, std::index_sequence<Is...>, F&& f) {
131
  return WithConstructedImplF<T, F>{std::forward<F>(f)}(
132
      std::get<Is>(std::forward<Tuple>(t))...);
133
}
134
135
template <class T, size_t... Is>
136
auto TupleRefImpl(T&& t, std::index_sequence<Is...>)
137
    -> decltype(std::forward_as_tuple(std::get<Is>(std::forward<T>(t))...)) {
138
  // NOLINTNEXTLINE(bugprone-use-after-move)
139
  return std::forward_as_tuple(std::get<Is>(std::forward<T>(t))...);
140
}
141
142
// Returns a tuple of references to the elements of the input tuple. T must be a
143
// tuple.
144
template <class T>
145
auto TupleRef(T&& t) -> decltype(TupleRefImpl(
146
    std::forward<T>(t),
147
    std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>())) {
148
  return TupleRefImpl(
149
      std::forward<T>(t),
150
      std::make_index_sequence<std::tuple_size<std::decay_t<T>>::value>());
151
}
152
153
template <class F, class K, class V>
154
decltype(std::declval<F>()(std::declval<const K&>(), std::piecewise_construct,
155
                           std::declval<std::tuple<K>>(), std::declval<V>()))
156
DecomposePairImpl(F&& f, std::pair<std::tuple<K>, V> p) {
157
  const auto& key = std::get<0>(p.first);
158
  return std::forward<F>(f)(key, std::piecewise_construct, std::move(p.first),
159
                            std::move(p.second));
160
}
161
162
}  // namespace memory_internal
163
164
// Constructs T into uninitialized storage pointed by `ptr` using the args
165
// specified in the tuple.
166
template <class Alloc, class T, class Tuple>
167
void ConstructFromTuple(Alloc* alloc, T* ptr, Tuple&& t) {
168
  memory_internal::ConstructFromTupleImpl(
169
      alloc, ptr, std::forward<Tuple>(t),
170
      std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>());
171
}
172
173
// Constructs T using the args specified in the tuple and calls F with the
174
// constructed value.
175
template <class T, class Tuple, class F>
176
decltype(std::declval<F>()(std::declval<T>())) WithConstructed(Tuple&& t,
177
                                                               F&& f) {
178
  return memory_internal::WithConstructedImpl<T>(
179
      std::forward<Tuple>(t),
180
      std::make_index_sequence<std::tuple_size<std::decay_t<Tuple>>::value>(),
181
      std::forward<F>(f));
182
}
183
184
// Given arguments of an std::pair's constructor, PairArgs() returns a pair of
185
// tuples with references to the passed arguments. The tuples contain
186
// constructor arguments for the first and the second elements of the pair.
187
//
188
// The following two snippets are equivalent.
189
//
190
// 1. std::pair<F, S> p(args...);
191
//
192
// 2. auto a = PairArgs(args...);
193
//    std::pair<F, S> p(std::piecewise_construct,
194
//                      std::move(a.first), std::move(a.second));
195
0
inline std::pair<std::tuple<>, std::tuple<>> PairArgs() { return {}; }
196
template <class F, class S>
197
std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(F&& f, S&& s) {
198
  return {std::piecewise_construct, std::forward_as_tuple(std::forward<F>(f)),
199
          std::forward_as_tuple(std::forward<S>(s))};
200
}
201
template <class F, class S>
202
std::pair<std::tuple<const F&>, std::tuple<const S&>> PairArgs(
203
    const std::pair<F, S>& p) {
204
  return PairArgs(p.first, p.second);
205
}
206
template <class F, class S>
207
std::pair<std::tuple<F&&>, std::tuple<S&&>> PairArgs(std::pair<F, S>&& p) {
208
  return PairArgs(std::forward<F>(p.first), std::forward<S>(p.second));
209
}
210
template <class F, class S>
211
auto PairArgs(std::piecewise_construct_t, F&& f, S&& s)
212
    -> decltype(std::make_pair(memory_internal::TupleRef(std::forward<F>(f)),
213
                               memory_internal::TupleRef(std::forward<S>(s)))) {
214
  return std::make_pair(memory_internal::TupleRef(std::forward<F>(f)),
215
                        memory_internal::TupleRef(std::forward<S>(s)));
216
}
217
218
// A helper function for implementing apply() in map policies.
219
template <class F, class... Args>
220
auto DecomposePair(F&& f, Args&&... args)
221
    -> decltype(memory_internal::DecomposePairImpl(
222
        std::forward<F>(f), PairArgs(std::forward<Args>(args)...))) {
223
  return memory_internal::DecomposePairImpl(
224
      std::forward<F>(f), PairArgs(std::forward<Args>(args)...));
225
}
226
227
// A helper function for implementing apply() in set policies.
228
template <class F, class Arg>
229
decltype(std::declval<F>()(std::declval<const Arg&>(), std::declval<Arg>()))
230
DecomposeValue(F&& f, Arg&& arg) {
231
  const auto& key = arg;
232
  return std::forward<F>(f)(key, std::forward<Arg>(arg));
233
}
234
235
// Helper functions for asan and msan.
236
451k
inline void SanitizerPoisonMemoryRegion(const void* m, size_t s) {
237
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
238
  ASAN_POISON_MEMORY_REGION(m, s);
239
#endif
240
#ifdef ABSL_HAVE_MEMORY_SANITIZER
241
  __msan_poison(m, s);
242
#endif
243
451k
  (void)m;
244
451k
  (void)s;
245
451k
}
246
247
9.84M
inline void SanitizerUnpoisonMemoryRegion(const void* m, size_t s) {
248
#ifdef ABSL_HAVE_ADDRESS_SANITIZER
249
  ASAN_UNPOISON_MEMORY_REGION(m, s);
250
#endif
251
#ifdef ABSL_HAVE_MEMORY_SANITIZER
252
  __msan_unpoison(m, s);
253
#endif
254
9.84M
  (void)m;
255
9.84M
  (void)s;
256
9.84M
}
257
258
template <typename T>
259
inline void SanitizerPoisonObject(const T* object) {
260
  SanitizerPoisonMemoryRegion(object, sizeof(T));
261
}
262
263
template <typename T>
264
inline void SanitizerUnpoisonObject(const T* object) {
265
  SanitizerUnpoisonMemoryRegion(object, sizeof(T));
266
}
267
268
namespace memory_internal {
269
270
// If Pair is a standard-layout type, OffsetOf<Pair>::kFirst and
271
// OffsetOf<Pair>::kSecond are equivalent to offsetof(Pair, first) and
272
// offsetof(Pair, second) respectively. Otherwise they are -1.
273
//
274
// The purpose of OffsetOf is to avoid calling offsetof() on non-standard-layout
275
// type, which is non-portable.
276
template <class Pair, class = std::true_type>
277
struct OffsetOf {
278
  static constexpr size_t kFirst = static_cast<size_t>(-1);
279
  static constexpr size_t kSecond = static_cast<size_t>(-1);
280
};
281
282
template <class Pair>
283
struct OffsetOf<Pair, typename std::is_standard_layout<Pair>::type> {
284
  static constexpr size_t kFirst = offsetof(Pair, first);
285
  static constexpr size_t kSecond = offsetof(Pair, second);
286
};
287
288
template <class K, class V>
289
struct IsLayoutCompatible {
290
 private:
291
  struct Pair {
292
    K first;
293
    V second;
294
  };
295
296
  // Is P layout-compatible with Pair?
297
  template <class P>
298
  static constexpr bool LayoutCompatible() {
299
    return std::is_standard_layout<P>() && sizeof(P) == sizeof(Pair) &&
300
           alignof(P) == alignof(Pair) &&
301
           memory_internal::OffsetOf<P>::kFirst ==
302
               memory_internal::OffsetOf<Pair>::kFirst &&
303
           memory_internal::OffsetOf<P>::kSecond ==
304
               memory_internal::OffsetOf<Pair>::kSecond;
305
  }
306
307
 public:
308
  // Whether pair<const K, V> and pair<K, V> are layout-compatible. If they are,
309
  // then it is safe to store them in a union and read from either.
310
  static constexpr bool value = std::is_standard_layout<K>() &&
311
                                std::is_standard_layout<Pair>() &&
312
                                memory_internal::OffsetOf<Pair>::kFirst == 0 &&
313
                                LayoutCompatible<std::pair<K, V>>() &&
314
                                LayoutCompatible<std::pair<const K, V>>();
315
};
316
317
}  // namespace memory_internal
318
319
// The internal storage type for key-value containers like flat_hash_map.
320
//
321
// It is convenient for the value_type of a flat_hash_map<K, V> to be
322
// pair<const K, V>; the "const K" prevents accidental modification of the key
323
// when dealing with the reference returned from find() and similar methods.
324
// However, this creates other problems; we want to be able to emplace(K, V)
325
// efficiently with move operations, and similarly be able to move a
326
// pair<K, V> in insert().
327
//
328
// The solution is this union, which aliases the const and non-const versions
329
// of the pair. This also allows flat_hash_map<const K, V> to work, even though
330
// that has the same efficiency issues with move in emplace() and insert() -
331
// but people do it anyway.
332
//
333
// If kMutableKeys is false, only the value member can be accessed.
334
//
335
// If kMutableKeys is true, key can be accessed through all slots while value
336
// and mutable_value must be accessed only via INITIALIZED slots. Slots are
337
// created and destroyed via mutable_value so that the key can be moved later.
338
//
339
// Accessing one of the union fields while the other is active is safe as
340
// long as they are layout-compatible, which is guaranteed by the definition of
341
// kMutableKeys. For C++11, the relevant section of the standard is
342
// https://timsong-cpp.github.io/cppwp/n3337/class.mem#19 (9.2.19)
343
template <class K, class V>
344
union map_slot_type {
345
  map_slot_type() {}
346
  ~map_slot_type() = delete;
347
  using value_type = std::pair<const K, V>;
348
  using mutable_value_type =
349
      std::pair<std::remove_const_t<K>, std::remove_const_t<V>>;
350
351
  value_type value;
352
  mutable_value_type mutable_value;
353
  std::remove_const_t<K> key;
354
};
355
356
template <class K, class V>
357
struct map_slot_policy {
358
  using slot_type = map_slot_type<K, V>;
359
  using value_type = std::pair<const K, V>;
360
  using mutable_value_type =
361
      std::pair<std::remove_const_t<K>, std::remove_const_t<V>>;
362
363
 private:
364
  static void emplace(slot_type* slot) {
365
    // The construction of union doesn't do anything at runtime but it allows us
366
    // to access its members without violating aliasing rules.
367
    new (slot) slot_type;
368
  }
369
  // If pair<const K, V> and pair<K, V> are layout-compatible, we can accept one
370
  // or the other via slot_type. We are also free to access the key via
371
  // slot_type::key in this case.
372
  using kMutableKeys = memory_internal::IsLayoutCompatible<K, V>;
373
374
 public:
375
  static value_type& element(slot_type* slot) { return slot->value; }
376
  static const value_type& element(const slot_type* slot) {
377
    return slot->value;
378
  }
379
380
  static K& mutable_key(slot_type* slot) {
381
    // Still check for kMutableKeys so that we can avoid calling std::launder
382
    // unless necessary because it can interfere with optimizations.
383
    return kMutableKeys::value ? slot->key
384
                               : *std::launder(const_cast<K*>(
385
                                     std::addressof(slot->value.first)));
386
  }
387
388
  static const K& key(const slot_type* slot) {
389
    return kMutableKeys::value ? slot->key : slot->value.first;
390
  }
391
392
  template <class Allocator, class... Args>
393
  static void construct(Allocator* alloc, slot_type* slot, Args&&... args) {
394
    emplace(slot);
395
    if (kMutableKeys::value) {
396
      std::allocator_traits<Allocator>::construct(*alloc, &slot->mutable_value,
397
                                                  std::forward<Args>(args)...);
398
    } else {
399
      std::allocator_traits<Allocator>::construct(*alloc, &slot->value,
400
                                                  std::forward<Args>(args)...);
401
    }
402
  }
403
404
  // Construct this slot by moving from another slot.
405
  template <class Allocator>
406
  static void construct(Allocator* alloc, slot_type* slot, slot_type* other) {
407
    emplace(slot);
408
    if (kMutableKeys::value) {
409
      std::allocator_traits<Allocator>::construct(
410
          *alloc, &slot->mutable_value, std::move(other->mutable_value));
411
    } else {
412
      std::allocator_traits<Allocator>::construct(*alloc, &slot->value,
413
                                                  std::move(other->value));
414
    }
415
  }
416
417
  // Construct this slot by copying from another slot.
418
  template <class Allocator>
419
  static void construct(Allocator* alloc, slot_type* slot,
420
                        const slot_type* other) {
421
    emplace(slot);
422
    std::allocator_traits<Allocator>::construct(*alloc, &slot->value,
423
                                                other->value);
424
  }
425
426
  template <class Allocator>
427
  static auto destroy(Allocator* alloc, slot_type* slot) {
428
    if (kMutableKeys::value) {
429
      std::allocator_traits<Allocator>::destroy(*alloc, &slot->mutable_value);
430
    } else {
431
      std::allocator_traits<Allocator>::destroy(*alloc, &slot->value);
432
    }
433
    return IsDestructionTrivial<Allocator, value_type>();
434
  }
435
436
  template <class Allocator>
437
  static auto transfer(Allocator* alloc, slot_type* new_slot,
438
                       slot_type* old_slot) {
439
    // This should really just be
440
    // typename absl::is_trivially_relocatable<value_type>::type()
441
    // but std::pair is not trivially copyable in C++23 in some standard
442
    // library versions.
443
    // See https://github.com/llvm/llvm-project/pull/95444 for instance.
444
    auto is_relocatable = typename std::conjunction<
445
        absl::is_trivially_relocatable<typename value_type::first_type>,
446
        absl::is_trivially_relocatable<typename value_type::second_type>>::
447
        type();
448
449
    emplace(new_slot);
450
    if (is_relocatable) {
451
      // TODO(b/247130232,b/251814870): remove casts after fixing warnings.
452
      std::memcpy(static_cast<void*>(std::launder(&new_slot->value)),
453
                  static_cast<const void*>(&old_slot->value),
454
                  sizeof(value_type));
455
      return is_relocatable;
456
    }
457
458
    if (kMutableKeys::value) {
459
      std::allocator_traits<Allocator>::construct(
460
          *alloc, &new_slot->mutable_value, std::move(old_slot->mutable_value));
461
    } else {
462
      std::allocator_traits<Allocator>::construct(*alloc, &new_slot->value,
463
                                                  std::move(old_slot->value));
464
    }
465
    destroy(alloc, old_slot);
466
    return is_relocatable;
467
  }
468
};
469
470
// Suppress erroneous uninitialized memory errors on GCC. For example, GCC
471
// thinks that the call to slot_array() in find_or_prepare_insert() is reading
472
// uninitialized memory, but slot_array is only called there when the table is
473
// non-empty and this memory is initialized when the table is non-empty.
474
#if !defined(__clang__) && defined(__GNUC__)
475
#define ABSL_SWISSTABLE_IGNORE_UNINITIALIZED(x)                    \
476
  _Pragma("GCC diagnostic push")                                   \
477
      _Pragma("GCC diagnostic ignored \"-Wmaybe-uninitialized\"")  \
478
          _Pragma("GCC diagnostic ignored \"-Wuninitialized\"") x; \
479
  _Pragma("GCC diagnostic pop")
480
#define ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(x) \
481
  ABSL_SWISSTABLE_IGNORE_UNINITIALIZED(return x)
482
#else
483
#define ABSL_SWISSTABLE_IGNORE_UNINITIALIZED(x) x
484
115M
#define ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(x) return x
485
#endif
486
487
// Variadic arguments hash function that ignore the rest of the arguments.
488
// Useful for usage with policy traits.
489
template <class Hash, bool kIsDefault>
490
struct HashElement {
491
  HashElement(const Hash& h, size_t s) : hash(h), seed(s) {}
492
493
  template <class K, class... Args>
494
  size_t operator()(const K& key, Args&&...) const {
495
    if constexpr (kIsDefault) {
496
      // TODO(b/384509507): resolve `no header providing
497
      // "absl::hash_internal::SupportsHashWithSeed" is directly included`.
498
      // Maybe we should make "internal/hash.h" be a separate library.
499
      return absl::hash_internal::HashWithSeed().hash(hash, key, seed);
500
    }
501
    // NOLINTNEXTLINE(clang-diagnostic-sign-conversion)
502
    return hash(key) ^ seed;
503
  }
504
  const Hash& hash;
505
  size_t seed;
506
};
507
508
// No arguments function hash function for a specific key.
509
template <class Hash, class Key, bool kIsDefault>
510
struct HashKey {
511
  HashKey(const Hash& h, const Key& k) : hash(h), key(k) {}
512
513
  size_t operator()(size_t seed) const {
514
    return HashElement<Hash, kIsDefault>{hash, seed}(key);
515
  }
516
  const Hash& hash;
517
  const Key& key;
518
};
519
520
// Variadic arguments equality function that ignore the rest of the arguments.
521
// Useful for usage with policy traits.
522
template <class K1, class KeyEqual>
523
struct EqualElement {
524
  template <class K2, class... Args>
525
  bool operator()(const K2& lhs, Args&&...) const {
526
    ABSL_SWISSTABLE_IGNORE_UNINITIALIZED_RETURN(eq(lhs, rhs));
527
  }
528
  const K1& rhs;
529
  const KeyEqual& eq;
530
};
531
532
// Type erased function for computing hash of the slot.
533
using HashSlotFn = size_t (*)(const void* hash_fn, void* slot, size_t seed);
534
535
// Type erased function to apply `Fn` to data inside of the `slot`.
536
// The data is expected to have type `T`.
537
template <class Fn, class T, bool kIsDefault>
538
size_t TypeErasedApplyToSlotFn(const void* fn, void* slot, size_t seed) {
539
  const auto* f = static_cast<const Fn*>(fn);
540
  return HashElement<Fn, kIsDefault>{*f, seed}(*static_cast<const T*>(slot));
541
}
542
543
// Type erased function to apply `Fn` to data inside of the `*slot_ptr`.
544
// The data is expected to have type `T`.
545
template <class Fn, class T, bool kIsDefault>
546
size_t TypeErasedDerefAndApplyToSlotFn(const void* fn, void* slot_ptr,
547
                                       size_t seed) {
548
  const auto* f = static_cast<const Fn*>(fn);
549
  const T* slot = *static_cast<T**>(slot_ptr);
550
  return HashElement<Fn, kIsDefault>{*f, seed}(*slot);
551
}
552
553
// Type erased function to apply `Fn` to data inside of the `slot_ptr->first`.
554
// The data is expected to have type `T`.
555
template <class Fn, class T, bool kIsDefault>
556
size_t TypeErasedDerefAndApplyToSlotFirstFn(const void* fn, void* slot_ptr,
557
                                            size_t seed) {
558
  const auto* f = static_cast<const Fn*>(fn);
559
  const T* slot = *static_cast<T**>(slot_ptr);
560
  return HashElement<Fn, kIsDefault>{*f, seed}(slot->first);
561
}
562
563
}  // namespace container_internal
564
ABSL_NAMESPACE_END
565
}  // namespace absl
566
567
#endif  // ABSL_CONTAINER_INTERNAL_CONTAINER_MEMORY_H_