made boost::hash valid for composite_key_results when there's no template partial specialization

[SVN r29336]
This commit is contained in:
Joaquín M. López Muñoz 2005-06-01 13:19:46 +00:00
parent 5d4107a5fa
commit 8ae46eb0fd
2 changed files with 37 additions and 1 deletions

View File

@ -1231,6 +1231,33 @@ struct hash<boost::multi_index::composite_key_result<CompositeKey> >:
{
};
} /* namespace boost */
#else
/* Lacking template partial specialization, std::equal_to, std::less and
* std::greater will still work for composite_key_results although without
* tuple interoperability. To achieve the same graceful degrading with
* boost::hash, we define the appropriate hash_value overload.
*/
namespace boost{
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
namespace multi_index{
#endif
template<typename CompositeKey>
inline std::size_t hash_value(
const boost::multi_index::composite_key_result<CompositeKey>& x)
{
boost::multi_index::composite_key_result_hash<
boost::multi_index::composite_key_result<CompositeKey> > h;
return h(x);
}
#if !defined(BOOST_NO_ARGUMENT_DEPENDENT_LOOKUP)
} /* namespace multi_index */
#endif
} /* namespace boost */
#endif

View File

@ -1,6 +1,6 @@
/* Boost.MultiIndex test for composite_key.
*
* Copyright 2003-2004 Joaqu匤 M L<EFBFBD>ez Mu<EFBFBD>z.
* Copyright 2003-2005 Joaquín M López Muñoz.
* Distributed under the Boost Software License, Version 1.0.
* (See accompanying file LICENSE_1_0.txt or copy at
* http://www.boost.org/LICENSE_1_0.txt)
@ -626,4 +626,13 @@ void test_composite_key()
ch1(ck6(xystr(0,0,"hello")))==ch1(make_tuple(std::string("hello"),0,0)));
BOOST_CHECK(
ch1(ck6(xystr(4,5,"world")))==ch1(make_tuple(std::string("world"),4,5)));
typedef boost::hash<composite_key_result<ckey_t3> > ckeyres_hash_t;
ckeyres_hash_t crh;
BOOST_CHECK(
ch1(ck6(xystr(0,0,"hello")))==crh(ck6(xystr(0,0,"hello"))));
BOOST_CHECK(
ch1(ck6(xystr(4,5,"world")))==crh(ck6(xystr(4,5,"world"))));
}