Improve the unordered tests support for some older compilers.

Better testing of elements with equivalent keys.


[SVN r7458]
This commit is contained in:
Daniel James
2007-07-17 23:17:21 +00:00
parent 6af2b965bb
commit aabf1a408b
11 changed files with 176 additions and 20 deletions

View File

@@ -624,13 +624,14 @@ namespace exception
}
return (std::numeric_limits<std::size_t>::max)();
}
friend void swap(allocator<T>& x, allocator<T>& y)
{
std::swap(x.tag_, y.tag_);
}
};
template <class T>
void swap(allocator<T>& x, allocator<T>& y)
{
std::swap(x.tag_, y.tag_);
}
// It's pretty much impossible to write a compliant swap when these
// two can throw. So they don't.

View File

@@ -50,7 +50,6 @@ namespace test
(x1.tag1_ == x2.tag1_ && x1.tag2_ < x2.tag2_);
}
friend object generate(object const*) {
int* x = 0;
return object(generate(x), generate(x));
@@ -62,6 +61,44 @@ namespace test
}
};
// This object is usd to test how well the containers cope with equivalent keys.
class equivalent_object
{
friend class hash;
friend class equal_to;
friend class less;
int tag1_, tag2_;
public:
explicit equivalent_object(int t1 = 0, int t2 = 0) : tag1_(t1), tag2_(t2) {}
~equivalent_object() {
tag1_ = -1;
tag2_ = -1;
}
friend bool operator==(equivalent_object const& x1, equivalent_object const& x2) {
return x1.tag1_ == x2.tag1_;
}
friend bool operator!=(equivalent_object const& x1, equivalent_object const& x2) {
return x1.tag1_ != x2.tag1_;
}
friend bool operator<(equivalent_object const& x1, equivalent_object const& x2) {
return x1.tag1_ < x2.tag1_;
}
friend equivalent_object generate(equivalent_object const*) {
signed char* x = 0;
return equivalent_object(generate(x), generate(x));
}
friend std::ostream& operator<<(std::ostream& out, equivalent_object const& o)
{
return out<<"("<<o.tag1_<<","<<o.tag2_<<")";
}
};
class hash
{
int type_;
@@ -79,6 +116,10 @@ namespace test
}
}
std::size_t operator()(equivalent_object const& x) const {
return x.tag1_;
}
std::size_t operator()(int x) const {
return x;
}
@@ -109,6 +150,10 @@ namespace test
}
}
bool operator()(equivalent_object const& x1, equivalent_object const& x2) const {
return x1 < x2;
}
std::size_t operator()(int x1, int x2) const {
return x1 < x2;
}
@@ -135,6 +180,10 @@ namespace test
}
}
bool operator()(equivalent_object const& x1, equivalent_object const& x2) const {
return x1 == x2;
}
std::size_t operator()(int x1, int x2) const {
return x1 == x2;
}
@@ -359,6 +408,51 @@ namespace test
bool equivalent_impl(allocator<T> const& x, allocator<T> const& y, test::derived_type) {
return x == y;
}
#if BOOST_WORKAROUND(__GNUC__, < 3)
void swap(test::object& x, test::object& y) {
test::object tmp;
tmp = x;
x = y;
y = tmp;
}
void swap(test::equivalent_object& x, test::equivalent_object& y) {
test::equivalent_object tmp;
tmp = x;
x = y;
y = tmp;
}
void swap(test::hash& x, test::hash& y) {
test::hash tmp;
tmp = x;
x = y;
y = tmp;
}
void swap(test::less& x, test::less& y) {
test::less tmp;
tmp = x;
x = y;
y = tmp;
}
void swap(test::equal_to& x, test::equal_to& y) {
test::equal_to tmp;
tmp = x;
x = y;
y = tmp;
}
template <class T>
void swap(test::allocator<T>& x, test::allocator<T>& y) {
test::allocator<T> tmp;
tmp = x;
x = y;
y = tmp;
}
#endif
}
#endif