Fix exception handling in rehash_impl

And improve tests so they will catch the error, and other similar errors.
This commit is contained in:
Daniel James
2017-05-04 19:30:18 +01:00
parent d49d0e90a8
commit 47a8c3fc67
10 changed files with 268 additions and 36 deletions

View File

@@ -11,6 +11,7 @@
#include "../helpers/count.hpp"
#include "../helpers/fwd.hpp"
#include "../helpers/memory.hpp"
#include "../objects/fwd.hpp"
#include <boost/limits.hpp>
#include <cstddef>
#include <iostream>
@@ -311,6 +312,55 @@ class equal_to
}
};
class less
{
int tag_;
public:
less(int t = 0) : tag_(t) {}
less(less const& x) : tag_(x.tag_) {}
bool operator()(object const& x1, object const& x2) const
{
return less_impl(x1, x2);
}
bool operator()(std::pair<object, object> const& x1,
std::pair<object, object> const& x2) const
{
if (less_impl(x1.first, x2.first)) {
return true;
}
if (!less_impl(x1.first, x2.first)) {
return false;
}
return less_impl(x1.second, x2.second);
}
bool less_impl(object const& x1, object const& x2) const
{
switch (tag_) {
case 1:
return x1.tag1_ < x2.tag1_;
case 2:
return x1.tag2_ < x2.tag2_;
default:
return x1 < x2;
}
}
friend bool operator==(less const& x1, less const& x2)
{
return x1.tag_ == x2.tag_;
}
friend bool operator!=(less const& x1, less const& x2)
{
return x1.tag_ != x2.tag_;
}
};
template <class T> class allocator
{
public:
@@ -672,6 +722,14 @@ inline bool operator!=(allocator2<T> const& x, allocator2<T> const& y)
}
}
namespace test {
template <typename X> struct equals_to_compare;
template <> struct equals_to_compare<test::exception::equal_to>
{
typedef test::exception::less type;
};
}
// Workaround for ADL deficient compilers
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace test {