forked from boostorg/container_hash
In hash_fwd_test avoid a Borland bug by putting the test classes in a namespace.
Seems to break on gcc 2.95 though... Also use HASH_NAMESPACE instead of boost to allow tests to be run in 'std'. [SVN r32686]
This commit is contained in:
@@ -8,8 +8,12 @@
|
||||
#if defined(TEST_EXTENSIONS) && !defined(TEST_STD_INCLUDES)
|
||||
#include <boost/functional/hash_fwd.hpp>
|
||||
|
||||
#include <boost/config.hpp>
|
||||
#include <cstddef>
|
||||
#include <vector>
|
||||
|
||||
namespace test {
|
||||
|
||||
template <class T>
|
||||
struct test_type1
|
||||
{
|
||||
@@ -35,8 +39,8 @@ struct test_type2
|
||||
friend std::size_t hash_value(test_type2<T> const& x)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
boost::hash_combine(seed, x.value1);
|
||||
boost::hash_combine(seed, x.value2);
|
||||
HASH_NAMESPACE::hash_combine(seed, x.value1);
|
||||
HASH_NAMESPACE::hash_combine(seed, x.value2);
|
||||
return seed;
|
||||
}
|
||||
#endif
|
||||
@@ -52,39 +56,40 @@ struct test_type3
|
||||
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
|
||||
friend std::size_t hash_value(test_type3<T> const& x)
|
||||
{
|
||||
std::size_t seed = boost::hash_range(x.values.begin(), x.values.end());
|
||||
boost::hash_range(seed, x.values.begin(), x.values.end());
|
||||
std::size_t seed = HASH_NAMESPACE::hash_range(x.values.begin(), x.values.end());
|
||||
HASH_NAMESPACE::hash_range(seed, x.values.begin(), x.values.end());
|
||||
return seed;
|
||||
}
|
||||
#endif
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#if defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOPUP)
|
||||
|
||||
namespace boost
|
||||
{
|
||||
template <class T>
|
||||
std::size_t hash_value(test_type1<T> const& x)
|
||||
std::size_t hash_value(test::test_type1<T> const& x)
|
||||
{
|
||||
HASH_NAMESPACE::hash<T> hasher;
|
||||
return hasher(x.value);
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::size_t hash_value(test_type2<T> const& x)
|
||||
std::size_t hash_value(test::test_type2<T> const& x)
|
||||
{
|
||||
std::size_t seed = 0;
|
||||
boost::hash_combine(seed, x.value1);
|
||||
boost::hash_combine(seed, x.value2);
|
||||
HASH_NAMESPACE::hash_combine(seed, x.value1);
|
||||
HASH_NAMESPACE::hash_combine(seed, x.value2);
|
||||
return seed;
|
||||
}
|
||||
|
||||
template <class T>
|
||||
std::size_t hash_value(test_type3<T> const& x)
|
||||
std::size_t hash_value(test::test_type3<T> const& x)
|
||||
{
|
||||
std::size_t seed = boost::hash_range(x.values.begin(), x.values.end());
|
||||
boost::hash_range(seed, x.values.begin(), x.values.end());
|
||||
std::size_t seed = HASH_NAMESPACE::hash_range(x.values.begin(), x.values.end());
|
||||
HASH_NAMESPACE::hash_range(seed, x.values.begin(), x.values.end());
|
||||
return seed;
|
||||
}
|
||||
}
|
||||
|
@@ -12,40 +12,40 @@
|
||||
|
||||
#if defined(TEST_EXTENSIONS) && !defined(TEST_STD_INCLUDES)
|
||||
|
||||
#include <boost/functional/hash.hpp>
|
||||
#include <boost/functional/hash/hash.hpp>
|
||||
#include <string>
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fwd_test1)
|
||||
{
|
||||
test_type1<int> x(5);
|
||||
test_type1<std::string> y("Test");
|
||||
test::test_type1<int> x(5);
|
||||
test::test_type1<std::string> y("Test");
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
boost::hash<int>()(5),
|
||||
boost::hash<test_type1<int> >()(x));
|
||||
HASH_NAMESPACE::hash<int>()(5),
|
||||
HASH_NAMESPACE::hash<test::test_type1<int> >()(x));
|
||||
|
||||
BOOST_CHECK_EQUAL(
|
||||
boost::hash<std::string>()("Test"),
|
||||
boost::hash<test_type1<std::string> >()(y));
|
||||
HASH_NAMESPACE::hash<std::string>()("Test"),
|
||||
HASH_NAMESPACE::hash<test::test_type1<std::string> >()(y));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fwd_test2)
|
||||
{
|
||||
test_type2<int> x(5, 10);
|
||||
test_type2<std::string> y("Test1", "Test2");
|
||||
test::test_type2<int> x(5, 10);
|
||||
test::test_type2<std::string> y("Test1", "Test2");
|
||||
|
||||
std::size_t seed1 = 0;
|
||||
boost::hash_combine(seed1, 5);
|
||||
boost::hash_combine(seed1, 10);
|
||||
HASH_NAMESPACE::hash_combine(seed1, 5);
|
||||
HASH_NAMESPACE::hash_combine(seed1, 10);
|
||||
|
||||
std::size_t seed2 = 0;
|
||||
boost::hash_combine(seed2, std::string("Test1"));
|
||||
boost::hash_combine(seed2, std::string("Test2"));
|
||||
HASH_NAMESPACE::hash_combine(seed2, std::string("Test1"));
|
||||
HASH_NAMESPACE::hash_combine(seed2, std::string("Test2"));
|
||||
|
||||
BOOST_CHECK_EQUAL(seed1,
|
||||
boost::hash<test_type2<int> >()(x));
|
||||
HASH_NAMESPACE::hash<test::test_type2<int> >()(x));
|
||||
BOOST_CHECK_EQUAL(seed2,
|
||||
boost::hash<test_type2<std::string> >()(y));
|
||||
HASH_NAMESPACE::hash<test::test_type2<std::string> >()(y));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fwd_test3)
|
||||
@@ -63,19 +63,19 @@ BOOST_AUTO_TEST_CASE(fwd_test3)
|
||||
values2.push_back("Gummo");
|
||||
values2.push_back("Zeppo");
|
||||
|
||||
test_type3<int> x(values1.begin(), values1.end());
|
||||
test_type3<std::string> y(values2.begin(), values2.end());
|
||||
test::test_type3<int> x(values1.begin(), values1.end());
|
||||
test::test_type3<std::string> y(values2.begin(), values2.end());
|
||||
|
||||
std::size_t seed1 = boost::hash_range(values1.begin(), values1.end());
|
||||
boost::hash_range(seed1, values1.begin(), values1.end());
|
||||
std::size_t seed1 = HASH_NAMESPACE::hash_range(values1.begin(), values1.end());
|
||||
HASH_NAMESPACE::hash_range(seed1, values1.begin(), values1.end());
|
||||
|
||||
std::size_t seed2 = boost::hash_range(values2.begin(), values2.end());
|
||||
boost::hash_range(seed2, values2.begin(), values2.end());
|
||||
std::size_t seed2 = HASH_NAMESPACE::hash_range(values2.begin(), values2.end());
|
||||
HASH_NAMESPACE::hash_range(seed2, values2.begin(), values2.end());
|
||||
|
||||
BOOST_CHECK_EQUAL(seed1,
|
||||
boost::hash<test_type3<int> >()(x));
|
||||
HASH_NAMESPACE::hash<test::test_type3<int> >()(x));
|
||||
BOOST_CHECK_EQUAL(seed2,
|
||||
boost::hash<test_type3<std::string> >()(y));
|
||||
HASH_NAMESPACE::hash<test::test_type3<std::string> >()(y));
|
||||
}
|
||||
|
||||
#endif
|
||||
|
@@ -15,16 +15,16 @@ template <class T> void unused(T const&) {}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(fwd_test)
|
||||
{
|
||||
test_type1<int> x1(3);
|
||||
test_type1<std::string> y1("Black");
|
||||
test_type2<int> x2(25, 16);
|
||||
test_type2<std::string> y2("White", "Green");
|
||||
test::test_type1<int> x1(3);
|
||||
test::test_type1<std::string> y1("Black");
|
||||
test::test_type2<int> x2(25, 16);
|
||||
test::test_type2<std::string> y2("White", "Green");
|
||||
|
||||
std::vector<int> empty;
|
||||
std::vector<std::string> empty2;
|
||||
|
||||
test_type3<int> x3(empty.begin(), empty.end());
|
||||
test_type3<std::string> y3(empty2.begin(), empty2.end());
|
||||
test::test_type3<int> x3(empty.begin(), empty.end());
|
||||
test::test_type3<std::string> y3(empty2.begin(), empty2.end());
|
||||
|
||||
// Prevent gcc warnings:
|
||||
unused(x1); unused(x2); unused(x3);
|
||||
|
Reference in New Issue
Block a user