Unordered: Merge from trunk

- Avoid an incorrect MSVC unused variable warning in the tests.
- Remove a `try..catch`.
- Adjust SFINAE use to try to supprt g++ 3.4. Fixes #7175.
- Fix some use of rvalues.
- Extra info in `at_tests`.



[SVN r79868]
This commit is contained in:
Daniel James
2012-08-05 08:34:44 +00:00
parent d77453b7ad
commit 8683332b2c
3 changed files with 100 additions and 53 deletions

View File

@ -346,19 +346,20 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
template <typename A, typename B, typename A0, typename A1, typename A2> template <typename A, typename B, typename A0, typename A1, typename A2>
inline typename enable_if<piecewise3<A, B, A0>, void>::type inline typename enable_if<piecewise3<A, B, A0>, void>::type
construct_impl(std::pair<A, B>* address, A0&&, A1&& a1, A2&& a2) construct_impl(std::pair<A, B>* address,
BOOST_FWD_REF(A0), BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
{ {
boost::unordered::detail::construct_from_tuple( boost::unordered::detail::construct_from_tuple(
boost::addressof(address->first), a1); boost::addressof(address->first), boost::forward<A1>(a1));
boost::unordered::detail::construct_from_tuple( boost::unordered::detail::construct_from_tuple(
boost::addressof(address->second), a2); boost::addressof(address->second), boost::forward<A2>(a2));
} }
#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) #if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT)
template <typename A, typename B, typename A0> template <typename A, typename B, typename A0>
inline typename enable_if<emulation1<A, B, A0>, void>::type inline typename enable_if<emulation1<A, B, A0>, void>::type
construct_impl(std::pair<A, B>* address, A0&& a0) construct_impl(std::pair<A, B>* address, BOOST_FWD_REF(A0) a0)
{ {
new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0)); new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0));
new((void*) boost::addressof(address->second)) B(); new((void*) boost::addressof(address->second)) B();
@ -366,7 +367,8 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
template <typename A, typename B, typename A0, typename A1, typename A2> template <typename A, typename B, typename A0, typename A1, typename A2>
inline typename enable_if<emulation3<A, B, A0>, void>::type inline typename enable_if<emulation3<A, B, A0>, void>::type
construct_impl(std::pair<A, B>* address, A0&& a0, A1&& a1, A2&& a2) construct_impl(std::pair<A, B>* address,
BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2)
{ {
new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0)); new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0));
new((void*) boost::addressof(address->second)) B( new((void*) boost::addressof(address->second)) B(
@ -378,7 +380,8 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
typename A0, typename A1, typename A2, typename A3, typename A0, typename A1, typename A2, typename A3,
typename... Args> typename... Args>
inline void construct_impl(std::pair<A, B>* address, inline void construct_impl(std::pair<A, B>* address,
A0&& a0, A1&& a1, A2&& a2, A3&& a3, Args&&... args) BOOST_FWD_REF(A0) a0, BOOST_FWD_REF(A1) a1, BOOST_FWD_REF(A2) a2,
BOOST_FWD_REF(A3) a3, BOOST_FWD_REF(Args)... args)
{ {
new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0)); new((void*) boost::addressof(address->first)) A(boost::forward<A0>(a0));
@ -390,6 +393,7 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
} }
#endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT #endif // BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT
#else // BOOST_NO_VARIADIC_TEMPLATES #else // BOOST_NO_VARIADIC_TEMPLATES
//////////////////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////////////////
@ -441,9 +445,9 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
#undef BOOST_UNORDERED_CONSTRUCT_IMPL #undef BOOST_UNORDERED_CONSTRUCT_IMPL
template <typename A, typename B, typename A0, typename A1, typename A2> template <typename A, typename B, typename A0, typename A1, typename A2>
inline typename enable_if<piecewise3<A, B, A0>, void>::type inline void construct_impl(std::pair<A, B>* address,
construct_impl(std::pair<A, B>* address, boost::unordered::detail::emplace_args3<A0, A1, A2> const& args,
boost::unordered::detail::emplace_args3<A0, A1, A2> const& args) typename enable_if<piecewise3<A, B, A0>, void*>::type = 0)
{ {
boost::unordered::detail::construct_from_tuple( boost::unordered::detail::construct_from_tuple(
boost::addressof(address->first), args.a1); boost::addressof(address->first), args.a1);
@ -454,9 +458,9 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
#if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT) #if defined(BOOST_UNORDERED_DEPRECATED_PAIR_CONSTRUCT)
template <typename A, typename B, typename A0> template <typename A, typename B, typename A0>
inline typename enable_if<emulation1<A, B, A0>, void>::type inline void construct_impl(std::pair<A, B>* address,
construct_impl(std::pair<A, B>* address, boost::unordered::detail::emplace_args1<A0> const& args,
boost::unordered::detail::emplace_args1<A0> const& args) typename enable_if<emulation1<A, B, A0>, void*>::type = 0)
{ {
new((void*) boost::addressof(address->first)) A( new((void*) boost::addressof(address->first)) A(
boost::forward<A0>(args.a0)); boost::forward<A0>(args.a0));
@ -464,9 +468,9 @@ BOOST_UNORDERED_CONSTRUCT_FROM_TUPLE(10, boost::)
} }
template <typename A, typename B, typename A0, typename A1, typename A2> template <typename A, typename B, typename A0, typename A1, typename A2>
inline typename enable_if<emulation3<A, B, A0>, void>::type inline void construct_impl(std::pair<A, B>* address,
construct_impl(std::pair<A, B>* address, boost::unordered::detail::emplace_args3<A0, A1, A2> const& args,
boost::unordered::detail::emplace_args3<A0, A1, A2> const& args) typename enable_if<emulation3<A, B, A0>, void*>::type = 0)
{ {
new((void*) boost::addressof(address->first)) A( new((void*) boost::addressof(address->first)) A(
boost::forward<A0>(args.a0)); boost::forward<A0>(args.a0));
@ -811,35 +815,38 @@ namespace boost { namespace unordered { namespace detail {
# endif # endif
template <typename Alloc> template <typename Alloc>
inline typename boost::enable_if_c< inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
typename boost::enable_if_c<
boost::unordered::detail:: boost::unordered::detail::
has_select_on_container_copy_construction<Alloc>::value, Alloc has_select_on_container_copy_construction<Alloc>::value, void*
>::type call_select_on_container_copy_construction(const Alloc& rhs) >::type = 0)
{ {
return rhs.select_on_container_copy_construction(); return rhs.select_on_container_copy_construction();
} }
template <typename Alloc> template <typename Alloc>
inline typename boost::disable_if_c< inline Alloc call_select_on_container_copy_construction(const Alloc& rhs,
typename boost::disable_if_c<
boost::unordered::detail:: boost::unordered::detail::
has_select_on_container_copy_construction<Alloc>::value, Alloc has_select_on_container_copy_construction<Alloc>::value, void*
>::type call_select_on_container_copy_construction(const Alloc& rhs) >::type = 0)
{ {
return rhs; return rhs;
} }
template <typename SizeType, typename Alloc> template <typename SizeType, typename Alloc>
inline typename boost::enable_if_c< inline SizeType call_max_size(const Alloc& a,
boost::unordered::detail::has_max_size<Alloc>::value, SizeType typename boost::enable_if_c<
>::type call_max_size(const Alloc& a) boost::unordered::detail::has_max_size<Alloc>::value, void*
>::type = 0)
{ {
return a.max_size(); return a.max_size();
} }
template <typename SizeType, typename Alloc> template <typename SizeType, typename Alloc>
inline typename boost::disable_if_c< inline SizeType call_max_size(const Alloc&, typename boost::disable_if_c<
boost::unordered::detail::has_max_size<Alloc>::value, SizeType boost::unordered::detail::has_max_size<Alloc>::value, void*
>::type call_max_size(const Alloc&) >::type = 0)
{ {
return (std::numeric_limits<SizeType>::max)(); return (std::numeric_limits<SizeType>::max)();
} }
@ -967,41 +974,41 @@ namespace boost { namespace unordered { namespace detail {
// the only construct method that old fashioned allocators support. // the only construct method that old fashioned allocators support.
template <typename T> template <typename T>
static typename boost::enable_if_c< static void construct(Alloc& a, T* p, T const& x,
boost::unordered::detail::has_construct<Alloc, T>::value && typename boost::enable_if_c<
boost::is_same<T, value_type>::value boost::unordered::detail::has_construct<Alloc, T>::value &&
>::type boost::is_same<T, value_type>::value,
construct(Alloc& a, T* p, T const& x) void*>::type = 0)
{ {
a.construct(p, x); a.construct(p, x);
} }
template <typename T> template <typename T>
static typename boost::disable_if_c< static void construct(Alloc&, T* p, T const& x,
typename boost::disable_if_c<
boost::unordered::detail::has_construct<Alloc, T>::value && boost::unordered::detail::has_construct<Alloc, T>::value &&
boost::is_same<T, value_type>::value boost::is_same<T, value_type>::value,
>::type void*>::type = 0)
construct(Alloc&, T* p, T const& x)
{ {
new ((void*) p) T(x); new ((void*) p) T(x);
} }
template <typename T> template <typename T>
static typename boost::enable_if_c< static void destroy(Alloc& a, T* p,
typename boost::enable_if_c<
boost::unordered::detail::has_destroy<Alloc, T>::value && boost::unordered::detail::has_destroy<Alloc, T>::value &&
boost::is_same<T, value_type>::value boost::is_same<T, value_type>::value,
>::type void*>::type = 0)
destroy(Alloc& a, T* p)
{ {
a.destroy(p); a.destroy(p);
} }
template <typename T> template <typename T>
static typename boost::disable_if_c< static void destroy(Alloc&, T* p,
typename boost::disable_if_c<
boost::unordered::detail::has_destroy<Alloc, T>::value && boost::unordered::detail::has_destroy<Alloc, T>::value &&
boost::is_same<T, value_type>::value boost::is_same<T, value_type>::value,
>::type void*>::type = 0)
destroy(Alloc&, T* p)
{ {
boost::unordered::detail::destroy(p); boost::unordered::detail::destroy(p);
} }
@ -1120,17 +1127,42 @@ namespace boost { namespace unordered { namespace detail {
#else #else
template <typename AllocTraits, typename T>
struct value_construct
{
typedef BOOST_DEDUCED_TYPENAME AllocTraits::allocator_type allocator;
allocator& alloc;
T* ptr;
value_construct(allocator& a, T* p) : alloc(a), ptr(p)
{
AllocTraits::construct(alloc, ptr, T());
}
void release()
{
ptr = 0;
}
~value_construct()
{
if (ptr) AllocTraits::destroy(alloc, ptr);
}
private:
value_construct(value_construct const&);
value_construct& operator=(value_construct const&);
};
template <typename Alloc, typename T, BOOST_UNORDERED_EMPLACE_TEMPLATE> template <typename Alloc, typename T, BOOST_UNORDERED_EMPLACE_TEMPLATE>
inline void construct_node(Alloc& a, T* p, BOOST_UNORDERED_EMPLACE_ARGS) inline void construct_node(Alloc& a, T* p, BOOST_UNORDERED_EMPLACE_ARGS)
{ {
boost::unordered::detail::allocator_traits<Alloc>::construct(a, p, T()); value_construct<boost::unordered::detail::allocator_traits<Alloc>, T>
try { construct_guard(a, p);
boost::unordered::detail::construct_impl( boost::unordered::detail::construct_impl(
p->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD); p->value_ptr(), BOOST_UNORDERED_EMPLACE_FORWARD);
} catch(...) { construct_guard.release();
boost::unordered::detail::allocator_traits<Alloc>::destroy(a, p);
throw;
}
} }
template <typename Alloc, typename T> template <typename Alloc, typename T>

View File

@ -26,7 +26,9 @@ namespace test
template <class T> class allocator2; template <class T> class allocator2;
object generate(object const*); object generate(object const*);
implicitly_convertible generate(implicitly_convertible const*); implicitly_convertible generate(implicitly_convertible const*);
inline void ignore_variable(void const*) {}
class object : private counted_object class object : private counted_object
{ {
friend class hash; friend class hash;
@ -248,6 +250,9 @@ namespace test
void destroy(T* p) { void destroy(T* p) {
//detail::tracker.track_destroy((void*) p, sizeof(T), tag_); //detail::tracker.track_destroy((void*) p, sizeof(T), tag_);
p->~T(); p->~T();
// Work around MSVC buggy unused parameter warning.
ignore_variable(&p);
} }
bool operator==(allocator1 const& x) const bool operator==(allocator1 const& x) const

View File

@ -13,21 +13,31 @@
namespace at_tests { namespace at_tests {
UNORDERED_AUTO_TEST(at_tests) { UNORDERED_AUTO_TEST(at_tests) {
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Create Map" << std::endl;
boost::unordered_map<std::string, int> x; boost::unordered_map<std::string, int> x;
typedef boost::unordered_map<std::string, int>::iterator iterator; typedef boost::unordered_map<std::string, int>::iterator iterator;
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Add elements" << std::endl;
x["one"] = 1; x["one"] = 1;
x["two"] = 2; x["two"] = 2;
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Check existing elements" << std::endl;
BOOST_TEST(x.at("one") == 1); BOOST_TEST(x.at("one") == 1);
BOOST_TEST(x.at("two") == 2); BOOST_TEST(x.at("two") == 2);
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Check missing element" << std::endl;
try { try {
x.at("three"); x.at("three");
BOOST_ERROR("Should have thrown."); BOOST_ERROR("Should have thrown.");
} }
catch(std::out_of_range) { catch(std::out_of_range) {
} }
BOOST_LIGHTWEIGHT_TEST_OSTREAM << "Finished" << std::endl;
} }
} }