diff --git a/include/boost/unordered/detail/buckets.hpp b/include/boost/unordered/detail/buckets.hpp index 4f25ebb6..4fb1f503 100644 --- a/include/boost/unordered/detail/buckets.hpp +++ b/include/boost/unordered/detail/buckets.hpp @@ -574,7 +574,8 @@ namespace boost { namespace unordered { namespace detail { inline typename boost::disable_if, void>::type construct_impl(void* address, Arg1&& arg1, Arg2&& arg2, Args&&... args) { - new(address) T(std::forward(arg1, arg2, args)...); + new(address) T(std::forward(arg1), std::forward(arg2), + std::forward(args)...); } template @@ -582,7 +583,8 @@ namespace boost { namespace unordered { namespace detail { construct_impl(void* address, Arg1&& arg1, Arg2&& arg2, Args&&... args) { new(address) T(std::forward(arg1), - typename T::second_type(std::forward(arg2, args)...)); + typename T::second_type( + std::forward(arg2), std::forward(args)...)); } #else diff --git a/test/unordered/insert_tests.cpp b/test/unordered/insert_tests.cpp index 8f8c58a9..2ea3a40a 100644 --- a/test/unordered/insert_tests.cpp +++ b/test/unordered/insert_tests.cpp @@ -516,14 +516,24 @@ UNORDERED_AUTO_TEST(insert_initializer_list_multimap) struct overloaded_constructor { - overloaded_constructor(int x = 1, int y = 2, int z = 3) - : x(x), y(y), z(z) {} + overloaded_constructor(int x1 = 1, int x2 = 2, int x3 = 3, int x4 = 4) + : x1(x1), x2(x2), x3(x3), x4(x4) {} - int x, y, z; + int x1, x2, x3, x4; bool operator==(overloaded_constructor const& rhs) const { - return x == rhs.x && y == rhs.y && z == rhs.z; + return x1 == rhs.x1 && x2 == rhs.x2 && x3 == rhs.x3 && x4 == rhs.x4; + } + + friend std::size_t hash_value(overloaded_constructor const& x) + { + std::size_t hash = 0; + boost::hash_combine(hash, x.x1); + boost::hash_combine(hash, x.x2); + boost::hash_combine(hash, x.x3); + boost::hash_combine(hash, x.x4); + return hash; } }; @@ -554,6 +564,35 @@ UNORDERED_AUTO_TEST(map_emplace_test) x.find(7)->second == overloaded_constructor(8, 9, 10)); } +UNORDERED_AUTO_TEST(set_emplace_test) +{ + boost::unordered_set x; + overloaded_constructor check; + + x.emplace(); + BOOST_TEST(x.find(check) != x.end() && *x.find(check) == check); + + x.clear(); + x.emplace(1); + check = overloaded_constructor(1); + BOOST_TEST(x.find(check) != x.end() && *x.find(check) == check); + + x.clear(); + x.emplace(2, 3); + check = overloaded_constructor(2, 3); + BOOST_TEST(x.find(check) != x.end() && *x.find(check) == check); + + x.clear(); + x.emplace(4, 5, 6); + check = overloaded_constructor(4, 5, 6); + BOOST_TEST(x.find(check) != x.end() && *x.find(check) == check); + + x.clear(); + x.emplace(7, 8, 9, 10); + check = overloaded_constructor(7, 8, 9, 10); + BOOST_TEST(x.find(check) != x.end() && *x.find(check) == check); +} + } RUN_TESTS()