mirror of
https://github.com/boostorg/unordered.git
synced 2025-07-29 19:07:15 +02:00
Unordered: Test types that are only destructible.
[SVN r73820]
This commit is contained in:
@ -21,6 +21,7 @@ namespace test
|
||||
{
|
||||
namespace minimal
|
||||
{
|
||||
class destructible;
|
||||
class copy_constructible;
|
||||
class copy_constructible_equality_comparable;
|
||||
class default_copy_constructible;
|
||||
@ -35,10 +36,25 @@ namespace minimal
|
||||
template <class T> class allocator;
|
||||
template <class T> class cxx11_allocator;
|
||||
|
||||
struct constructor_param
|
||||
{
|
||||
operator int() const { return 0; }
|
||||
};
|
||||
|
||||
class destructible
|
||||
{
|
||||
public:
|
||||
destructible(constructor_param const&) {}
|
||||
~destructible() {}
|
||||
private:
|
||||
destructible(destructible const&);
|
||||
destructible& operator=(destructible const&);
|
||||
};
|
||||
|
||||
class copy_constructible
|
||||
{
|
||||
public:
|
||||
static copy_constructible create() { return copy_constructible(); }
|
||||
copy_constructible(constructor_param const&) {}
|
||||
copy_constructible(copy_constructible const&) {}
|
||||
~copy_constructible() {}
|
||||
private:
|
||||
@ -49,9 +65,7 @@ namespace minimal
|
||||
class copy_constructible_equality_comparable
|
||||
{
|
||||
public:
|
||||
static copy_constructible_equality_comparable create() {
|
||||
return copy_constructible_equality_comparable();
|
||||
}
|
||||
copy_constructible_equality_comparable(constructor_param const&) {}
|
||||
|
||||
copy_constructible_equality_comparable(
|
||||
copy_constructible_equality_comparable const&)
|
||||
@ -86,10 +100,7 @@ namespace minimal
|
||||
class default_copy_constructible
|
||||
{
|
||||
public:
|
||||
static default_copy_constructible create()
|
||||
{
|
||||
return default_copy_constructible();
|
||||
}
|
||||
default_copy_constructible(constructor_param const&) {}
|
||||
|
||||
default_copy_constructible()
|
||||
{
|
||||
@ -106,13 +117,14 @@ namespace minimal
|
||||
private:
|
||||
default_copy_constructible& operator=(
|
||||
default_copy_constructible const&);
|
||||
ampersand_operator_used operator&() const { return ampersand_operator_used(); }
|
||||
ampersand_operator_used operator&() const {
|
||||
return ampersand_operator_used(); }
|
||||
};
|
||||
|
||||
class assignable
|
||||
{
|
||||
public:
|
||||
static assignable create() { return assignable(); }
|
||||
assignable(constructor_param const&) {}
|
||||
assignable(assignable const&) {}
|
||||
assignable& operator=(assignable const&) { return *this; }
|
||||
~assignable() {}
|
||||
@ -127,7 +139,7 @@ namespace minimal
|
||||
class hash
|
||||
{
|
||||
public:
|
||||
static hash create() { return hash<T>(); }
|
||||
hash(constructor_param const&) {}
|
||||
hash() {}
|
||||
hash(hash const&) {}
|
||||
hash& operator=(hash const&) { return *this; }
|
||||
@ -142,7 +154,7 @@ namespace minimal
|
||||
class equal_to
|
||||
{
|
||||
public:
|
||||
static equal_to create() { return equal_to<T>(); }
|
||||
equal_to(constructor_param const&) {}
|
||||
equal_to() {}
|
||||
equal_to(equal_to const&) {}
|
||||
equal_to& operator=(equal_to const&) { return *this; }
|
||||
|
@ -45,11 +45,11 @@ template class boost::unordered_multimap<
|
||||
|
||||
UNORDERED_AUTO_TEST(test0)
|
||||
{
|
||||
test::minimal::constructor_param x;
|
||||
|
||||
typedef std::pair<test::minimal::assignable const,
|
||||
test::minimal::copy_constructible> value_type;
|
||||
value_type value(
|
||||
test::minimal::assignable::create(),
|
||||
test::minimal::copy_constructible::create());
|
||||
value_type value(x, x);
|
||||
|
||||
std::cout<<"Test unordered_map.\n";
|
||||
|
||||
@ -179,14 +179,12 @@ UNORDERED_AUTO_TEST(test1) {
|
||||
|
||||
UNORDERED_AUTO_TEST(test2)
|
||||
{
|
||||
test::minimal::assignable assignable
|
||||
= test::minimal::assignable::create();
|
||||
test::minimal::copy_constructible copy_constructible
|
||||
= test::minimal::copy_constructible::create();
|
||||
test::minimal::hash<test::minimal::assignable> hash
|
||||
= test::minimal::hash<test::minimal::assignable>::create();
|
||||
test::minimal::equal_to<test::minimal::assignable> equal_to
|
||||
= test::minimal::equal_to<test::minimal::assignable>::create();
|
||||
test::minimal::constructor_param x;
|
||||
|
||||
test::minimal::assignable assignable(x);
|
||||
test::minimal::copy_constructible copy_constructible(x);
|
||||
test::minimal::hash<test::minimal::assignable> hash(x);
|
||||
test::minimal::equal_to<test::minimal::assignable> equal_to(x);
|
||||
|
||||
typedef std::pair<test::minimal::assignable const,
|
||||
test::minimal::copy_constructible> map_value_type;
|
||||
|
@ -41,7 +41,9 @@ template class boost::unordered_multiset<
|
||||
|
||||
UNORDERED_AUTO_TEST(test0)
|
||||
{
|
||||
test::minimal::assignable assignable = test::minimal::assignable::create();
|
||||
test::minimal::constructor_param x;
|
||||
|
||||
test::minimal::assignable assignable(x);
|
||||
|
||||
std::cout<<"Test unordered_set.\n";
|
||||
|
||||
@ -163,14 +165,12 @@ UNORDERED_AUTO_TEST(test1)
|
||||
|
||||
UNORDERED_AUTO_TEST(test2)
|
||||
{
|
||||
test::minimal::assignable assignable
|
||||
= test::minimal::assignable::create();
|
||||
test::minimal::copy_constructible copy_constructible
|
||||
= test::minimal::copy_constructible::create();
|
||||
test::minimal::hash<test::minimal::assignable> hash
|
||||
= test::minimal::hash<test::minimal::assignable>::create();
|
||||
test::minimal::equal_to<test::minimal::assignable> equal_to
|
||||
= test::minimal::equal_to<test::minimal::assignable>::create();
|
||||
test::minimal::constructor_param x;
|
||||
|
||||
test::minimal::assignable assignable(x);
|
||||
test::minimal::copy_constructible copy_constructible(x);
|
||||
test::minimal::hash<test::minimal::assignable> hash(x);
|
||||
test::minimal::equal_to<test::minimal::assignable> equal_to(x);
|
||||
|
||||
std::cout<<"Test unordered_set.\n";
|
||||
|
||||
@ -197,4 +197,31 @@ UNORDERED_AUTO_TEST(test2)
|
||||
unordered_test(multiset, assignable, assignable, hash, equal_to);
|
||||
}
|
||||
|
||||
UNORDERED_AUTO_TEST(destructible_tests)
|
||||
{
|
||||
test::minimal::constructor_param x;
|
||||
|
||||
test::minimal::destructible destructible(x);
|
||||
test::minimal::hash<test::minimal::destructible> hash(x);
|
||||
test::minimal::equal_to<test::minimal::destructible> equal_to(x);
|
||||
|
||||
std::cout<<"Test unordered_set.\n";
|
||||
|
||||
boost::unordered_set<
|
||||
test::minimal::destructible,
|
||||
test::minimal::hash<test::minimal::destructible>,
|
||||
test::minimal::equal_to<test::minimal::destructible> > set;
|
||||
|
||||
unordered_destructible_test(set);
|
||||
|
||||
std::cout<<"Test unordered_multiset.\n";
|
||||
|
||||
boost::unordered_multiset<
|
||||
test::minimal::destructible,
|
||||
test::minimal::hash<test::minimal::destructible>,
|
||||
test::minimal::equal_to<test::minimal::destructible> > multiset;
|
||||
|
||||
unordered_destructible_test(multiset);
|
||||
}
|
||||
|
||||
RUN_TESTS()
|
||||
|
@ -28,6 +28,7 @@ typedef long double comparison_type;
|
||||
|
||||
template <class T> void sink(T const&) {}
|
||||
template <class T> T rvalue(T const& v) { return v; }
|
||||
template <class T> T rvalue_default() { return T(); }
|
||||
|
||||
template <class X, class T>
|
||||
void container_test(X& r, T const&)
|
||||
@ -109,15 +110,48 @@ void container_test(X& r, T const&)
|
||||
BOOST_TEST(X().size() == 0);
|
||||
|
||||
X a,b;
|
||||
X a_const;
|
||||
|
||||
sink(X(a));
|
||||
X u2(a);
|
||||
X u3 = a;
|
||||
|
||||
a.swap(b);
|
||||
boost::swap(a, b);
|
||||
test::check_return_type<X>::equals_ref(r = a);
|
||||
|
||||
// Allocator
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
|
||||
test::check_return_type<allocator_type>::equals(a_const.get_allocator());
|
||||
|
||||
// Avoid unused variable warnings:
|
||||
|
||||
sink(u);
|
||||
sink(u2);
|
||||
sink(u3);
|
||||
}
|
||||
|
||||
template <class X>
|
||||
void unordered_destructible_test(X&)
|
||||
{
|
||||
typedef BOOST_DEDUCED_TYPENAME X::iterator iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME X::const_iterator const_iterator;
|
||||
typedef BOOST_DEDUCED_TYPENAME X::size_type size_type;
|
||||
|
||||
X x1;
|
||||
|
||||
#if !defined(BOOST_NO_RVALUE_REFERENCES)
|
||||
X x2(rvalue_default<X>());
|
||||
X x3 = rvalue_default<X>();
|
||||
x2 = rvalue_default<X>();
|
||||
#endif
|
||||
|
||||
X* ptr = new X();
|
||||
X& a1 = *ptr;
|
||||
(&a1)->~X();
|
||||
|
||||
X a,b;
|
||||
X const a_const;
|
||||
test::check_return_type<iterator>::equals(a.begin());
|
||||
test::check_return_type<const_iterator>::equals(a_const.begin());
|
||||
@ -130,7 +164,7 @@ void container_test(X& r, T const&)
|
||||
|
||||
a.swap(b);
|
||||
boost::swap(a, b);
|
||||
test::check_return_type<X>::equals_ref(r = a);
|
||||
|
||||
test::check_return_type<size_type>::equals(a.size());
|
||||
test::check_return_type<size_type>::equals(a.max_size());
|
||||
test::check_return_type<bool>::convertible(a.empty());
|
||||
@ -139,12 +173,6 @@ void container_test(X& r, T const&)
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME X::allocator_type allocator_type;
|
||||
test::check_return_type<allocator_type>::equals(a_const.get_allocator());
|
||||
|
||||
// Avoid unused variable warnings:
|
||||
|
||||
sink(u);
|
||||
sink(u2);
|
||||
sink(u3);
|
||||
}
|
||||
|
||||
template <class X, class Key>
|
||||
@ -215,8 +243,10 @@ void unordered_map_functions(X&, Key const& k, T const&)
|
||||
}
|
||||
|
||||
template <class X, class Key, class T, class Hash, class Pred>
|
||||
void unordered_test(X&, Key& k, T& t, Hash& hf, Pred& eq)
|
||||
void unordered_test(X& x, Key& k, T& t, Hash& hf, Pred& eq)
|
||||
{
|
||||
unordered_destructible_test(x);
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME X::key_type key_type;
|
||||
typedef BOOST_DEDUCED_TYPENAME X::hasher hasher;
|
||||
typedef BOOST_DEDUCED_TYPENAME X::key_equal key_equal;
|
||||
|
Reference in New Issue
Block a user