Merge in support for equality operators for the unordered containers and

hopefully better cross-platform support.

Merged revisions 44778-44835,44837-44918 via svnmerge from 
https://svn.boost.org/svn/boost/branches/unordered/trunk

........
  r44778 | danieljames | 2008-04-26 17:15:44 +0100 (Sat, 26 Apr 2008) | 2 lines
  
  Remove a trailing comma.
........
  r44779 | danieljames | 2008-04-26 17:23:51 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Merge in support for equality operators.
........
  r44780 | danieljames | 2008-04-26 17:28:44 +0100 (Sat, 26 Apr 2008) | 1 line
  
  Use my own list container to avoid working around STL container bugs.
........
  r44833 | danieljames | 2008-04-28 08:03:43 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Better equality tests.
........
  r44834 | danieljames | 2008-04-28 08:04:03 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Remove a superfluous check.
........
  r44835 | danieljames | 2008-04-28 08:04:21 +0100 (Mon, 28 Apr 2008) | 1 line
  
  Add equality reference documentation.
........
  r44916 | danieljames | 2008-04-30 08:16:52 +0100 (Wed, 30 Apr 2008) | 1 line
  
  New version of list.hpp
........
  r44917 | danieljames | 2008-04-30 08:18:31 +0100 (Wed, 30 Apr 2008) | 1 line
  
  Support compilers without ADL in the compile tests.
........
  r44918 | danieljames | 2008-04-30 08:25:20 +0100 (Wed, 30 Apr 2008) | 7 lines
  
  Change the typedef of buffered functions as it was confusing MSVC 6.5
  
  get_allocator wasn't compiling when the allocator workaround is used because it
  couldn't cast from the wrapped allocator to an allocator of another type. So
  use value_alloc_ when it's available (it's only unavailable on compilers with
  C++0x support, which don't require the workaround).
........


[SVN r44919]
This commit is contained in:
Daniel James
2008-04-30 07:57:04 +00:00
parent 94932ae026
commit b5db48b6a4
21 changed files with 745 additions and 99 deletions
+9 -14
View File
@@ -8,10 +8,10 @@
#include <boost/unordered_map.hpp>
#include <boost/unordered_set.hpp>
#include <vector>
#include <algorithm>
#include "./metafunctions.hpp"
#include "./fwd.hpp"
#include "./list.hpp"
namespace test
{
@@ -56,20 +56,17 @@ namespace test
BOOST_DEDUCED_TYPENAME Container::key_equal key_equal_;
float max_load_factor_;
typedef BOOST_DEDUCED_TYPENAME non_const_value_type<Container>::type value_type;
std::vector<value_type> values_;
typedef test::list<BOOST_DEDUCED_TYPENAME Container::value_type>
value_list;
value_list values_;
public:
unordered_equivalence_tester(Container const &x)
: size_(x.size()),
hasher_(x.hash_function()), key_equal_(x.key_eq()),
max_load_factor_(x.max_load_factor()),
values_()
values_(x.begin(), x.end())
{
// Can't initialise values_ straight from x because of Visual C++ 6
values_.reserve(x.size());
std::copy(x.begin(), x.end(), std::back_inserter(values_));
std::sort(values_.begin(), values_.end());
values_.sort();
}
bool operator()(Container const& x) const
@@ -80,11 +77,9 @@ namespace test
(max_load_factor_ == x.max_load_factor()) &&
(values_.size() == x.size()))) return false;
std::vector<value_type> copy;
copy.reserve(x.size());
std::copy(x.begin(), x.end(), std::back_inserter(copy));
std::sort(copy.begin(), copy.end());
return(std::equal(values_.begin(), values_.end(), copy.begin()));
value_list copy(x.begin(), x.end());
copy.sort();
return values_ == copy;
}
private:
unordered_equivalence_tester();
-29
View File
@@ -75,35 +75,6 @@ namespace test
sizeof(has_unique_key_impl((Container const*)0))
== sizeof(no_type));
};
// Non Const Value Type
template <bool IsMap>
struct non_const_value_type_impl
{
template <class Container>
struct apply {
typedef std::pair<
BOOST_DEDUCED_TYPENAME Container::key_type,
BOOST_DEDUCED_TYPENAME Container::mapped_type> type;
};
};
template<>
struct non_const_value_type_impl<false>
{
template <class Container>
struct apply {
typedef BOOST_DEDUCED_TYPENAME Container::value_type type;
};
};
template <class Container>
struct non_const_value_type
: non_const_value_type_impl< ::test::is_map<Container>::value>::
BOOST_NESTED_TEMPLATE apply<Container>
{
};
}
#endif
+2 -2
View File
@@ -6,7 +6,7 @@
#if !defined(BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER)
#define BOOST_UNORDERED_TEST_HELPERS_RANDOM_VALUES_HEADER
#include <list>
#include "./list.hpp"
#include <algorithm>
#include <boost/mpl/if.hpp>
#include "./generators.hpp"
@@ -97,7 +97,7 @@ namespace test
template <class X>
struct random_values
: public std::list<BOOST_DEDUCED_TYPENAME X::value_type>
: public test::list<BOOST_DEDUCED_TYPENAME X::value_type>
{
random_values(int count, test::random_generator const& generator =
test::default_generator)
+5 -5
View File
@@ -7,10 +7,10 @@
#define BOOST_UNORDERED_TEST_HELPERS_STRONG_HEADER
#include <boost/config.hpp>
#include <vector>
#include <iterator>
#include "./metafunctions.hpp"
#include "./equivalent.hpp"
#include "./list.hpp"
#include "../objects/exception.hpp"
namespace test
@@ -18,19 +18,19 @@ namespace test
template <class X>
class strong
{
typedef std::vector<BOOST_DEDUCED_TYPENAME non_const_value_type<X>::type> values_type;
typedef test::list<BOOST_DEDUCED_TYPENAME X::value_type> values_type;
values_type values_;
public:
void store(X const& x) {
DISABLE_EXCEPTIONS;
values_.clear();
values_.reserve(x.size());
std::copy(x.cbegin(), x.cend(), std::back_inserter(values_));
values_.insert(x.cbegin(), x.cend());
}
void test(X const& x) const {
if(!(x.size() == values_.size() &&
std::equal(x.cbegin(), x.cend(), values_.begin(), test::equivalent)))
std::equal(x.cbegin(), x.cend(), values_.begin(),
test::equivalent)))
BOOST_ERROR("Strong exception safety failure.");
}
};
+1 -1
View File
@@ -61,7 +61,7 @@ namespace test {
for(registered_test_base* i = first(); i; i = i->next)
i->run();
}
};
}
}
#endif
+13 -18
View File
@@ -11,7 +11,6 @@
#include <set>
#include <map>
#include <vector>
#include <iterator>
#include <algorithm>
#include <boost/mpl/if.hpp>
@@ -22,6 +21,7 @@
#include "./metafunctions.hpp"
#include "./helpers.hpp"
#include "./equivalent.hpp"
#include "./list.hpp"
namespace test
{
@@ -44,27 +44,23 @@ namespace test
template <class X1, class X2>
void compare_range(X1 const& x1, X2 const& x2)
{
std::vector<BOOST_DEDUCED_TYPENAME non_const_value_type<X1>::type> values1, values2;
values1.reserve(x1.size());
values2.reserve(x2.size());
std::copy(x1.begin(), x1.end(), std::back_inserter(values1));
std::copy(x2.begin(), x2.end(), std::back_inserter(values2));
std::sort(values1.begin(), values1.end());
std::sort(values2.begin(), values2.end());
typedef test::list<BOOST_DEDUCED_TYPENAME X1::value_type> value_list;
value_list values1(x1.begin(), x1.end());
value_list values2(x2.begin(), x2.end());
values1.sort();
values2.sort();
BOOST_CHECK(values1.size() == values2.size() &&
std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent));
std::equal(values1.begin(), values1.end(), values2.begin(),
test::equivalent));
}
template <class X1, class X2, class T>
void compare_pairs(X1 const& x1, X2 const& x2, T*)
{
std::vector<T> values1, values2;
values1.reserve(std::distance(x1.first, x1.second));
values2.reserve(std::distance(x2.first, x2.second));
std::copy(x1.first, x1.second, std::back_inserter(values1));
std::copy(x2.first, x2.second, std::back_inserter(values2));
std::sort(values1.begin(), values1.end());
std::sort(values2.begin(), values2.end());
test::list<T> values1(x1.first, x1.second);
test::list<T> values2(x2.first, x2.second);
values1.sort();
values2.sort();
BOOST_CHECK(values1.size() == values2.size() &&
std::equal(values1.begin(), values1.end(), values2.begin(), test::equivalent));
}
@@ -123,8 +119,7 @@ namespace test
compare_pairs(
x.equal_range(get_key<X>(val)),
this->equal_range(get_key<X>(val)),
(BOOST_DEDUCED_TYPENAME non_const_value_type<X>::type*) 0
);
(BOOST_DEDUCED_TYPENAME X::value_type*) 0);
}
template <class It>