Unordered: Fix more calls to std::forward.

[SVN r74086]
This commit is contained in:
Daniel James
2011-08-27 11:29:04 +00:00
parent bd13f2b1ad
commit 9ae19a64d7
2 changed files with 47 additions and 6 deletions

View File

@ -574,7 +574,8 @@ namespace boost { namespace unordered { namespace detail {
inline typename boost::disable_if<emulated_pair_constructor<T>, void>::type
construct_impl(void* address, Arg1&& arg1, Arg2&& arg2, Args&&... args)
{
new(address) T(std::forward<Arg1, Arg2, Args>(arg1, arg2, args)...);
new(address) T(std::forward<Arg1>(arg1), std::forward<Arg2>(arg2),
std::forward<Args>(args)...);
}
template <class T, class Arg1, class Arg2, class... Args>
@ -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>(arg1),
typename T::second_type(std::forward<Arg2, Args>(arg2, args)...));
typename T::second_type(
std::forward<Arg2>(arg2), std::forward<Args>(args)...));
}
#else

View File

@ -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<overloaded_constructor> 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()