Prove relevance of strong typedef for node-based foa containers

This commit is contained in:
Christian Mazakas
2023-01-11 13:02:04 -08:00
parent 904e806b1e
commit 1e61423eac
2 changed files with 9 additions and 59 deletions

View File

@ -40,65 +40,15 @@ namespace boost {
static Key const& extract(value_type const& key) { return key; }
#if 0
using element_type = value_type*;
static value_type& value_from(element_type& x) { return *x; }
static Key const& extract(element_type k) { return *k; }
static element_type&& move(element_type& x) { return std::move(x); }
template <class A>
static void construct(A&, element_type* p, element_type&& x)
{
*p = x;
x = nullptr;
}
template <class A, class... Args>
static void construct(A& al, element_type* p, element_type const& x)
{
*p = boost::to_address(boost::allocator_allocate(al, 1));
try {
boost::allocator_construct(al, *p, *x);
} catch (...) {
boost::allocator_deallocate(al,
boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(**p),
1);
throw;
}
}
template <class A, class... Args>
static void construct(A& al, element_type* p, Args&&... args)
{
*p = boost::to_address(boost::allocator_allocate(al, 1));
try {
boost::allocator_construct(al, *p, std::forward<Args>(args)...);
} catch (...) {
boost::allocator_deallocate(al,
boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(**p),
1);
throw;
}
}
template <class A> static void destroy(A& al, element_type* p) noexcept
{
if (*p) {
boost::allocator_destroy(al, *p);
boost::allocator_deallocate(al,
boost::pointer_traits<
typename boost::allocator_pointer<A>::type>::pointer_to(**p),
1);
}
}
#else
struct element_type
{
value_type* p;
/*
* we use a defined copy constructor here so the type is no longer
* trivially copy-constructible which inhibits our memcpy
* optimizations when copying the tables
*/
element_type() : p(nullptr) {}
element_type(element_type const& rhs) : p(rhs.p) {}
};
@ -146,7 +96,6 @@ namespace boost {
1);
}
}
#endif
};
} // namespace detail

View File

@ -701,7 +701,7 @@ namespace insert_tests {
pointer_constructible(int x_) : x(x_) {}
pointer_constructible(pointer_constructible const& p) : x(p.x) {}
pointer_constructible(pointer_constructible* const&) : x(-1) {}
pointer_constructible(BOOST_RV_REF(pointer_constructible*)) : x(-2) {}
pointer_constructible(BOOST_RV_REF(pointer_constructible*)) : x(-1) {}
};
struct pointer_constructible_hash
@ -733,11 +733,12 @@ namespace insert_tests {
pointer_constructible_equal_to, test::allocator1<pointer_constructible> >
set, set2;
pointer_constructible pc(1337), *addr_pc = &pc;
pointer_constructible pc(1337);
pointer_constructible* const addr_pc = &pc;
set.insert(pc); // 1337
set.insert(addr_pc); // -1
set.insert(&pc); // -1
set.insert(addr_pc); // -1
BOOST_TEST_EQ(set.size(), 2u);
BOOST_TEST(set.find(pc) != set.end());