diff --git a/test/unordered/reserve_tests.cpp b/test/unordered/reserve_tests.cpp index bc3936cf..578f0dfc 100644 --- a/test/unordered/reserve_tests.cpp +++ b/test/unordered/reserve_tests.cpp @@ -20,24 +20,16 @@ std::size_t total_allocation = 0; std::size_t num_allocations = 0; -struct B -{ - B() : i(++count) {} - static int count; - int i; - bool operator==(B const& b) const { return i == b.i; }; - bool operator!=(B const& b) const { return i != b.i; }; -}; - -int B::count = 0; - -template struct A : B +template struct A { typedef T value_type; - A() {} + static int count; + int i; - template A(const A&) BOOST_NOEXCEPT {} + A() : i(++count) {} + + template A(const A& a) BOOST_NOEXCEPT : i(a.i) {} T* allocate(std::size_t n) { @@ -51,8 +43,13 @@ template struct A : B total_allocation -= n * sizeof(T); std::free(p); } + + bool operator==(A const& a) const { return i == a.i; }; + bool operator!=(A const& a) const { return i != a.i; }; }; +template int A::count = 0; + template void bucket_count_constructor() { BOOST_TEST_EQ(num_allocations, 0u); @@ -184,6 +181,30 @@ template void rehash_tests() } UNORDERED_AUTO_TEST (unordered_set_reserve) { + { + // prove Allocator invariants + // from cppref: + // Given: + // * A, an Allocator type for type T + // * B, the corresponding Allocator type for some cv-unqualified object type + // U (as obtained by rebinding A) + // + // Expression: + // A a(b) + // + // Return Type: + // Constructs `a` such that `B(a)==b` and `A(b)==a`. + // (Note: This implies that all allocators related by rebind maintain each + // other's resources, such as memory pools.) + // + // + typedef boost::allocator_rebind, float>::type alloc_rebound; + alloc_rebound b; + A a(b); + BOOST_ASSERT(alloc_rebound(a) == b); + BOOST_ASSERT(A(b) == a); + } + typedef boost::unordered_set, std::equal_to, A > unordered_set;