@@ -4990,14 +4990,143 @@ GTEST_TEST(hashmap, add_by_piecewise_construct_bitwise_same_type)
49904990 constexpr usize reserved_size = 2 ;
49914991 hashmap_type map;
49924992 map.reserve (reserved_size);
4993- // map.add(hud::tag_piecewise_construct, hud::forward_as_tuple(1), hud::forward_as_tuple(2));
4993+ const auto it = map.add (hud::tag_piecewise_construct, hud::forward_as_tuple (1 ), hud::forward_as_tuple (2 ));
4994+ return hud::tuple {
4995+ map.count () == 1 , // 0
4996+ it->key () == 1 , // 1
4997+ it->value () == 2 // 2
4998+ };
4999+ };
5000+
5001+ // Non constant
5002+ {
5003+ const auto result = test ();
5004+ hud_assert_true (hud::get<0 >(result));
5005+ hud_assert_true (hud::get<1 >(result));
5006+ hud_assert_true (hud::get<2 >(result));
5007+ }
5008+
5009+ // Constant
5010+ {
5011+ constexpr auto result = test ();
5012+ hud_assert_true (hud::get<0 >(result));
5013+ hud_assert_true (hud::get<1 >(result));
5014+ hud_assert_true (hud::get<2 >(result));
5015+ }
5016+ }
5017+
5018+ GTEST_TEST (hashmap, add_by_piecewise_construct_bitwise_different_type)
5019+ {
5020+ using key_type = i32 ;
5021+ using value_type = i64 ;
5022+ using other_key_type = u32 ;
5023+ using other_value_type = u64 ;
5024+ using hashmap_type = hud::hashmap<key_type, value_type, hud::hash_64<key_type>, hud::equal<key_type>, hud_test::allocator_watcher<1 >>;
5025+
5026+ const auto test = []()
5027+ {
5028+ constexpr usize reserved_size = 2 ;
5029+ hashmap_type map;
5030+ map.reserve (reserved_size);
5031+ const auto it = map.add (hud::tag_piecewise_construct, hud::forward_as_tuple (other_key_type {1 }), hud::forward_as_tuple (other_value_type {2 }));
5032+
5033+ return hud::tuple {
5034+ map.count () == 1 , // 0
5035+ it->key () == 1 , // 1
5036+ it->value () == 2 // 2
5037+ };
5038+ };
5039+
5040+ // Non constant
5041+ {
5042+ const auto result = test ();
5043+ hud_assert_true (hud::get<0 >(result));
5044+ hud_assert_true (hud::get<1 >(result));
5045+ hud_assert_true (hud::get<2 >(result));
5046+ }
5047+
5048+ // Constant
5049+ {
5050+ constexpr auto result = test ();
5051+ hud_assert_true (hud::get<0 >(result));
5052+ hud_assert_true (hud::get<1 >(result));
5053+ hud_assert_true (hud::get<2 >(result));
5054+ }
5055+ }
5056+
5057+ GTEST_TEST (hashmap, add_by_piecewise_construct_non_bitwise_same_type)
5058+ {
5059+ using key_type = hud_test::non_bitwise_type;
5060+ using value_type = hud_test::non_bitwise_type;
5061+ using hashmap_type = hud::hashmap<key_type, value_type, hud::hash_64<key_type>, hud::equal<key_type>, hud_test::allocator_watcher<1 >>;
5062+
5063+ static_assert (hud::is_hashable_64_v<key_type, hud::tuple<i32 , i32 *>>);
5064+ static_assert (hud::is_comparable_with_equal_v<key_type, hud::tuple<i32 , i32 *>>);
5065+
5066+ const auto test = []()
5067+ {
5068+ constexpr usize reserved_size = 2 ;
5069+ i32 ptr[2 ];
5070+ hashmap_type map;
5071+ map.reserve (reserved_size);
5072+ const auto it = map.add (hud::tag_piecewise_construct, hud::forward_as_tuple (1 , ptr), hud::forward_as_tuple (2 , ptr + 1 ));
5073+
5074+ return hud::tuple {
5075+ map.count () == 1 , // 0
5076+ it->key ().constructor_count () == 1 , // 1
5077+ it->key ().move_constructor_count () == 0 , // 2
5078+ it->key ().copy_constructor_count () == 0 , // 3
5079+ it->key ().move_assign_count () == 0 , // 4
5080+ it->key ().copy_assign_count () == 0 , // 5
5081+ it->key ().id () == 1 , // 6
5082+ it->key ().destructor_counter () == ptr, // 7
5083+ it->value ().constructor_count () == 1 , // 8
5084+ it->value ().move_constructor_count () == 0 , // 9
5085+ it->value ().copy_constructor_count () == 0 , // 10
5086+ it->value ().move_assign_count () == 0 , // 11
5087+ it->value ().copy_assign_count () == 0 , // 12
5088+ it->value ().id () == 2 , // 13
5089+ it->value ().destructor_counter () == ptr + 1 // 14
5090+ };
49945091 };
49955092
49965093 // Non constant
49975094 {
5095+ const auto result = test ();
5096+ hud_assert_true (hud::get<0 >(result));
5097+ hud_assert_true (hud::get<1 >(result));
5098+ hud_assert_true (hud::get<2 >(result));
5099+ hud_assert_true (hud::get<3 >(result));
5100+ hud_assert_true (hud::get<4 >(result));
5101+ hud_assert_true (hud::get<5 >(result));
5102+ hud_assert_true (hud::get<6 >(result));
5103+ hud_assert_true (hud::get<7 >(result));
5104+ hud_assert_true (hud::get<8 >(result));
5105+ hud_assert_true (hud::get<9 >(result));
5106+ hud_assert_true (hud::get<10 >(result));
5107+ hud_assert_true (hud::get<11 >(result));
5108+ hud_assert_true (hud::get<12 >(result));
5109+ hud_assert_true (hud::get<13 >(result));
5110+ hud_assert_true (hud::get<14 >(result));
49985111 }
49995112
50005113 // Constant
50015114 {
5115+ constexpr auto result = test ();
5116+ hud_assert_true (hud::get<0 >(result));
5117+ hud_assert_true (hud::get<1 >(result));
5118+ hud_assert_true (hud::get<2 >(result));
5119+ hud_assert_true (hud::get<3 >(result));
5120+ hud_assert_true (hud::get<4 >(result));
5121+ hud_assert_true (hud::get<5 >(result));
5122+ hud_assert_true (hud::get<6 >(result));
5123+ hud_assert_true (hud::get<7 >(result));
5124+ hud_assert_true (hud::get<8 >(result));
5125+ hud_assert_true (hud::get<9 >(result));
5126+ hud_assert_true (hud::get<10 >(result));
5127+ hud_assert_true (hud::get<11 >(result));
5128+ hud_assert_true (hud::get<12 >(result));
5129+ hud_assert_true (hud::get<13 >(result));
5130+ hud_assert_true (hud::get<14 >(result));
50025131 }
50035132}
0 commit comments