forked from boostorg/unordered
Improved support for Visual C++.
[SVN r2985]
This commit is contained in:
@@ -14,32 +14,35 @@
|
||||
|
||||
namespace test
|
||||
{
|
||||
struct base_type {} base;
|
||||
struct derived_type : base_type {} derived;
|
||||
|
||||
template <class T1, class T2>
|
||||
bool equivalent_impl(T1 const& x, T2 const& y) {
|
||||
bool equivalent_impl(T1 const& x, T2 const& y, base_type) {
|
||||
return x == y;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool equivalent_impl(boost::hash<T> const&, boost::hash<T> const&) {
|
||||
bool equivalent_impl(boost::hash<T> const&, boost::hash<T> const&, derived_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
bool equivalent_impl(std::equal_to<T> const&, std::equal_to<T> const&) {
|
||||
bool equivalent_impl(std::equal_to<T> const&, std::equal_to<T> const&, derived_type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
template <class T1, class T2, class T3, class T4>
|
||||
bool equivalent_impl(std::pair<T1, T2> const& x1,
|
||||
std::pair<T3, T4> const& x2) {
|
||||
return equivalent_impl(x1.first, x2.first) &&
|
||||
equivalent_impl(x1.second, x2.second);
|
||||
std::pair<T3, T4> const& x2, derived_type) {
|
||||
return equivalent_impl(x1.first, x2.first, derived) &&
|
||||
equivalent_impl(x1.second, x2.second, derived);
|
||||
}
|
||||
|
||||
struct equivalent_type {
|
||||
template <class T1, class T2>
|
||||
bool operator()(T1 const& x, T2 const& y) {
|
||||
return equivalent_impl(x, y);
|
||||
return equivalent_impl(x, y, derived);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,8 +77,8 @@ namespace test
|
||||
bool operator()(Container const& x) const
|
||||
{
|
||||
if(!((size_ == x.size()) &&
|
||||
(test::equivalent_impl(hasher_, x.hash_function())) &&
|
||||
(test::equivalent_impl(key_equal_, x.key_eq())) &&
|
||||
(test::equivalent(hasher_, x.hash_function())) &&
|
||||
(test::equivalent(key_equal_, x.key_eq())) &&
|
||||
(max_load_factor_ == x.max_load_factor()) &&
|
||||
(values_.size() == x.size()))) return false;
|
||||
|
||||
|
||||
@@ -11,18 +11,24 @@
|
||||
#include <string>
|
||||
#include <utility>
|
||||
|
||||
#if 0
|
||||
#include <boost/random/inversive_congruential.hpp>
|
||||
#include <boost/random/uniform_int.hpp>
|
||||
#include <boost/random/lagged_fibonacci.hpp>
|
||||
#include <boost/random/uniform_real.hpp>
|
||||
#include <boost/random/variate_generator.hpp>
|
||||
#else
|
||||
#include <cstdlib>
|
||||
#endif
|
||||
|
||||
#include "./fwd.hpp"
|
||||
|
||||
namespace test
|
||||
{
|
||||
#if 0
|
||||
typedef boost::hellekalek1995 integer_generator_type;
|
||||
typedef boost::lagged_fibonacci607 real_generator_type;
|
||||
#endif
|
||||
|
||||
template <class T>
|
||||
struct generator
|
||||
@@ -36,20 +42,30 @@ namespace test
|
||||
|
||||
inline int generate(int const*)
|
||||
{
|
||||
#if 0
|
||||
integer_generator_type gen;
|
||||
boost::uniform_int<> dist(0, 1000);
|
||||
static boost::variate_generator<integer_generator_type, boost::uniform_int<> >
|
||||
vg(gen, dist);
|
||||
return vg();
|
||||
#else
|
||||
using namespace std;
|
||||
return rand();
|
||||
#endif
|
||||
}
|
||||
|
||||
inline char generate(char const*)
|
||||
{
|
||||
#if 0
|
||||
integer_generator_type gen;
|
||||
boost::uniform_int<char> dist(32, 128);
|
||||
boost::uniform_int<char> dist(32, 127);
|
||||
static boost::variate_generator<integer_generator_type, boost::uniform_int<char> >
|
||||
vg(gen, dist);
|
||||
return vg();
|
||||
#else
|
||||
using namespace std;
|
||||
return rand() % (128 - 32) + 32;
|
||||
#endif
|
||||
}
|
||||
|
||||
inline std::string generate(std::string const*)
|
||||
@@ -74,11 +90,16 @@ namespace test
|
||||
|
||||
float generate(float const*)
|
||||
{
|
||||
#if 0
|
||||
real_generator_type gen;
|
||||
boost::uniform_real<float> dist;
|
||||
static boost::variate_generator<real_generator_type, boost::uniform_real<float> >
|
||||
vg(gen, dist);
|
||||
return vg();
|
||||
#else
|
||||
using namespace std;
|
||||
return (double) rand() / (double) RAND_MAX;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <class T1, class T2> std::pair<T1, T2> generate(
|
||||
|
||||
+21
-10
@@ -9,21 +9,32 @@
|
||||
namespace test
|
||||
{
|
||||
template <class Container>
|
||||
inline typename Container::key_type get_key(typename Container::key_type const& x)
|
||||
struct get_key_impl
|
||||
{
|
||||
return x;
|
||||
}
|
||||
typedef typename Container::key_type key_type;
|
||||
|
||||
template <class Container, class T>
|
||||
inline typename Container::key_type get_key(std::pair<typename Container::key_type const, T> const& x)
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
static key_type get_key(key_type const& x)
|
||||
{
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static key_type get_key(std::pair<key_type, T> const& x, char = 0)
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
static key_type get_key(std::pair<key_type const, T> const& x, unsigned char = 0)
|
||||
{
|
||||
return x.first;
|
||||
}
|
||||
};
|
||||
|
||||
template <class Container, class T>
|
||||
inline typename Container::key_type get_key(std::pair<typename Container::key_type, T> const& x)
|
||||
inline typename Container::key_type get_key(T const& x)
|
||||
{
|
||||
return x.first;
|
||||
return get_key_impl<Container>::get_key(x);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#define BOOST_UNORDERED_TEST_HELPERS_INVARIANT_HEADER
|
||||
|
||||
#include <set>
|
||||
#include <cmath>
|
||||
#include "./metafunctions.hpp"
|
||||
#include "./helpers.hpp"
|
||||
|
||||
@@ -80,7 +81,9 @@ namespace test
|
||||
// Finally, check that size matches up.
|
||||
if(x1.size() != size)
|
||||
BOOST_ERROR("x1.size() doesn't match actual size.");
|
||||
if(static_cast<float>(size) / static_cast<float>(x1.bucket_count()) != x1.load_factor())
|
||||
float load_factor = static_cast<float>(size) / static_cast<float>(x1.bucket_count());
|
||||
using namespace std;
|
||||
if(fabs(x1.load_factor() - load_factor) > x1.load_factor() / 64)
|
||||
BOOST_ERROR("x1.load_factor() doesn't match actual load_factor.");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,6 +16,8 @@
|
||||
#include <algorithm>
|
||||
#include <boost/mpl/if.hpp>
|
||||
#include <boost/mpl/eval_if.hpp>
|
||||
#include <boost/mpl/identity.hpp>
|
||||
#include <boost/type_traits/is_same.hpp>
|
||||
#include "../objects/fwd.hpp"
|
||||
#include "./metafunctions.hpp"
|
||||
#include "./helpers.hpp"
|
||||
@@ -24,15 +26,19 @@
|
||||
namespace test
|
||||
{
|
||||
template <class X>
|
||||
struct equals_to_compare
|
||||
struct equals_to_compare2
|
||||
: public boost::mpl::identity<std::less<typename X::first_argument_type> >
|
||||
{
|
||||
typedef std::less<typename X::first_argument_type> type;
|
||||
};
|
||||
|
||||
template <>
|
||||
struct equals_to_compare<test::equal_to>
|
||||
template <class X>
|
||||
struct equals_to_compare
|
||||
: public boost::mpl::eval_if<
|
||||
boost::is_same<X, test::equal_to>,
|
||||
boost::mpl::identity<test::less>,
|
||||
equals_to_compare2<X>
|
||||
>
|
||||
{
|
||||
typedef test::less type;
|
||||
};
|
||||
|
||||
template <class X1, class X2>
|
||||
@@ -121,13 +127,22 @@ namespace test
|
||||
(typename non_const_value_type<X>::type*) 0
|
||||
);
|
||||
}
|
||||
|
||||
template <class It>
|
||||
void insert_range(It begin, It end) {
|
||||
while(begin != end) {
|
||||
this->insert(*begin);
|
||||
++begin;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
template <class Equals>
|
||||
typename equals_to_compare<Equals>::type create_compare(
|
||||
Equals equals)
|
||||
Equals const& equals)
|
||||
{
|
||||
return typename equals_to_compare<Equals>::type();
|
||||
typename equals_to_compare<Equals>::type x;
|
||||
return x;
|
||||
}
|
||||
|
||||
template <class X>
|
||||
@@ -140,7 +155,7 @@ namespace test
|
||||
void check_container(X1 const& container, X2 const& values)
|
||||
{
|
||||
ordered<X1> tracker = create_ordered(container);
|
||||
tracker.insert(values.begin(), values.end());
|
||||
tracker.insert_range(values.begin(), values.end());
|
||||
tracker.compare(container);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user