Skip to content

Commit f2c5776

Browse files
committed
Fix usage of flat_hash_map with move only keys
1 parent e4c4385 commit f2c5776

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

absl/container/internal/container_memory.h

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -438,29 +438,26 @@ struct map_slot_policy {
438438
// but std::pair is not trivially copyable in C++23 in some standard
439439
// library versions.
440440
// See https://github.com/llvm/llvm-project/pull/95444 for instance.
441-
auto is_relocatable = typename std::conjunction<
441+
static constexpr auto kIsRelocatable = typename std::conjunction<
442442
absl::is_trivially_relocatable<typename value_type::first_type>,
443443
absl::is_trivially_relocatable<typename value_type::second_type>>::
444444
type();
445445

446446
emplace(new_slot);
447-
if (is_relocatable) {
447+
if constexpr (kIsRelocatable) {
448448
// TODO(b/247130232,b/251814870): remove casts after fixing warnings.
449449
std::memcpy(static_cast<void*>(std::launder(&new_slot->value)),
450450
static_cast<const void*>(&old_slot->value),
451451
sizeof(value_type));
452-
return is_relocatable;
453-
}
454-
455-
if (kMutableKeys::value) {
452+
} else if constexpr (kMutableKeys::value) {
456453
absl::allocator_traits<Allocator>::construct(
457454
*alloc, &new_slot->mutable_value, std::move(old_slot->mutable_value));
458455
} else {
459456
absl::allocator_traits<Allocator>::construct(*alloc, &new_slot->value,
460457
std::move(old_slot->value));
461458
}
462459
destroy(alloc, old_slot);
463-
return is_relocatable;
460+
return kIsRelocatable;
464461
}
465462
};
466463

0 commit comments

Comments
 (0)