@@ -389,7 +389,7 @@ struct map_slot_policy {
389389 template <class Allocator , class ... Args>
390390 static void construct (Allocator* alloc, slot_type* slot, Args&&... args) {
391391 emplace (slot);
392- if (kMutableKeys ::value) {
392+ if constexpr (kMutableKeys ::value) {
393393 absl::allocator_traits<Allocator>::construct (*alloc, &slot->mutable_value ,
394394 std::forward<Args>(args)...);
395395 } else {
@@ -402,7 +402,7 @@ struct map_slot_policy {
402402 template <class Allocator >
403403 static void construct (Allocator* alloc, slot_type* slot, slot_type* other) {
404404 emplace (slot);
405- if (kMutableKeys ::value) {
405+ if constexpr (kMutableKeys ::value) {
406406 absl::allocator_traits<Allocator>::construct (
407407 *alloc, &slot->mutable_value , std::move (other->mutable_value ));
408408 } else {
@@ -422,7 +422,7 @@ struct map_slot_policy {
422422
423423 template <class Allocator >
424424 static auto destroy (Allocator* alloc, slot_type* slot) {
425- if (kMutableKeys ::value) {
425+ if constexpr (kMutableKeys ::value) {
426426 absl::allocator_traits<Allocator>::destroy (*alloc, &slot->mutable_value );
427427 } else {
428428 absl::allocator_traits<Allocator>::destroy (*alloc, &slot->value );
@@ -438,29 +438,29 @@ 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) {
456- absl::allocator_traits<Allocator>::construct (
457- *alloc, &new_slot->mutable_value , std::move (old_slot->mutable_value ));
458452 } else {
459- absl::allocator_traits<Allocator>::construct (*alloc, &new_slot->value ,
460- std::move (old_slot->value ));
453+ if constexpr (kMutableKeys ::value) {
454+ absl::allocator_traits<Allocator>::construct (
455+ *alloc, &new_slot->mutable_value ,
456+ std::move (old_slot->mutable_value ));
457+ } else {
458+ absl::allocator_traits<Allocator>::construct (
459+ *alloc, &new_slot->value , std::move (old_slot->value ));
460+ }
461+ destroy (alloc, old_slot);
461462 }
462- destroy (alloc, old_slot);
463- return is_relocatable;
463+ return kIsRelocatable ;
464464 }
465465};
466466
0 commit comments