@@ -96,15 +96,9 @@ namespace hud
9696 };
9797
9898 template <typename key_t >
99- struct default_equal
100- : hud::equal<key_t >
101- {
102- };
99+ using default_equal = hud::equal<key_t >;
103100
104- struct default_allocator
105- : hud::heap_allocator
106- {
107- };
101+ using default_allocator = hud::heap_allocator;
108102
109103 /* * Retrives the H1 (57 first bit) of a hash. */
110104 [[nodiscard]]
@@ -579,55 +573,50 @@ namespace hud
579573 explicit constexpr hashset_impl () noexcept = default;
580574
581575 constexpr explicit hashset_impl (const allocator_type &allocator) noexcept
582- requires(hud::allocator_traits<allocator_type>::copy_when_container_copy::value)
583- : allocator_(allocator)
584- {
585- }
586-
587- constexpr explicit hashset_impl (const allocator_type &allocator) noexcept
588- requires(!hud::allocator_traits<allocator_type>::copy_when_container_copy::value)
589- : hashset_impl()
576+ : allocator_(hud::allocator_traits<allocator_type>::copy_when_container_copy::value ? allocator : allocator_type {})
590577 {
591578 }
592579
593580 constexpr explicit hashset_impl (const hashset_impl &other) noexcept
594- : allocator_(other.allocator())
581+ : allocator_(hud::allocator_traits<allocator_type>::copy_when_container_copy::value ? other.allocator() : allocator_type {} )
595582 , max_slot_count_(other.max_count())
596583 , count_(other.count())
597584 , free_slot_before_grow_(max_slot_before_grow(max_slot_count_) - count_)
598585 {
599586
600- // Allocate the buffer that will contain controls and aligned slots
601- // In a constant-evaluated context, bit_cast cannot be used with pointers
602- // To satisfy the compiler, allocate controls and slots in two separate allocations
603- usize control_size = allocate_control_and_slot (max_slot_count_);
604-
605- // If constant evaluated context
606- // loop through all slot and construct them regardless of the trivially constructible ( Maybe only for control_ptr_ ) like like grow_capacity
607- // In a non constant evaluated context
608- // If type is trivially copy constructible, just memcpy control and slot
609- // else do like grow_capacity
610- if (hud::is_constant_evaluated () || hud::is_trivially_copy_constructible_v<slot_type>)
587+ if (max_slot_count_ > 0 )
611588 {
612- // Set control to empty ending with sentinel
613- hud::memory::set (control_ptr_, control_size, empty_byte);
614- control_ptr_[max_slot_count_] = sentinel_byte;
615-
616- // Copy slots to newly allocated buffer
617- for (auto &slot : other)
589+ // Allocate the buffer that will contain controls and aligned slots
590+ // In a constant-evaluated context, bit_cast cannot be used with pointers
591+ // To satisfy the compiler, allocate controls and slots in two separate allocations
592+ usize control_size = allocate_control_and_slot (max_slot_count_);
593+
594+ // If constant evaluated context
595+ // loop through all slot and construct them regardless of the trivially constructible ( Maybe only for control_ptr_ ) like like grow_capacity
596+ // In a non constant evaluated context
597+ // If type is trivially copy constructible, just memcpy control and slot
598+ // else do like grow_capacity
599+ if (hud::is_constant_evaluated () || hud::is_trivially_copy_constructible_v<slot_type>)
618600 {
619- // Compute the hash
620- u64 hash = hasher_type {}(slot.key ());
621- // Find H1 slot index
622- u64 h1 = H1 (hash);
623- usize slot_index = find_first_empty_or_deleted (control_ptr_, max_slot_count_, h1);
624- // Save h2 in control h1 index
625- control::set_h2 (control_ptr_, slot_index, H2 (hash), max_slot_count_);
626- // Copy slot
627- hud::memory::construct_at (slot_ptr_ + slot_index, slot);
601+ // Set control to empty ending with sentinel
602+ hud::memory::set (control_ptr_, control_size, empty_byte);
603+ control_ptr_[max_slot_count_] = sentinel_byte;
604+
605+ // Copy slots to newly allocated buffer
606+ for (auto &slot : other)
607+ {
608+ // Compute the hash
609+ u64 hash = hasher_type {}(slot.key ());
610+ // Find H1 slot index
611+ u64 h1 = H1 (hash);
612+ usize slot_index = find_first_empty_or_deleted (control_ptr_, max_slot_count_, h1);
613+ // Save h2 in control h1 index
614+ control::set_h2 (control_ptr_, slot_index, H2 (hash), max_slot_count_);
615+ // Copy slot
616+ hud::memory::construct_at (slot_ptr_ + slot_index, slot);
617+ }
628618 }
629619 }
630-
631620 // Set control to empty ending with sentinel only if type is not trivially copyable
632621 // Int he case of trivially copyable type we just memcpy control and slots
633622 // if (!hud::is_trivially_copy_constructible_v<slot_type>)
0 commit comments