More general purpose support for iterators with odd reference type (trac #13501)

In the last release I added explicit support for `vector<bool>` which wasn't
working with libc++ because the iterator's `operator*` returned a proxy
reference type. Other implementations return a `bool` for const iterators, so
they happened to work okay.

This solves the problem in a more general purpose way by instantiating
`hash_combine` for the iterator `value_type`. So the type returned by
`operator*` will be implicitly casted to the correct type.
This commit is contained in:
Daniel James
2018-04-13 09:31:18 +01:00
parent 59f9543c10
commit 83a874ed49
2 changed files with 3 additions and 53 deletions

View File

@@ -22,7 +22,6 @@
#include <boost/detail/container_fwd.hpp>
#include <boost/core/enable_if.hpp>
#include <boost/static_assert.hpp>
#include <vector>
#if !defined(BOOST_NO_CXX11_HDR_ARRAY)
# include <array>
@@ -71,56 +70,6 @@ namespace boost
return seed;
}
inline std::size_t hash_range(
std::vector<bool>::iterator first,
std::vector<bool>::iterator last)
{
std::size_t seed = 0;
for(; first != last; ++first)
{
hash_combine<bool>(seed, *first);
}
return seed;
}
inline std::size_t hash_range(
std::vector<bool>::const_iterator first,
std::vector<bool>::const_iterator last)
{
std::size_t seed = 0;
for(; first != last; ++first)
{
hash_combine<bool>(seed, *first);
}
return seed;
}
inline void hash_range(
std::size_t& seed,
std::vector<bool>::iterator first,
std::vector<bool>::iterator last)
{
for(; first != last; ++first)
{
hash_combine<bool>(seed, *first);
}
}
inline void hash_range(
std::size_t& seed,
std::vector<bool>::const_iterator first,
std::vector<bool>::const_iterator last)
{
for(; first != last; ++first)
{
hash_combine<bool>(seed, *first);
}
}
template <class T, class A>
std::size_t hash_value(std::vector<T, A> const& v)
{

View File

@@ -18,6 +18,7 @@
#include <boost/container_hash/hash_fwd.hpp>
#include <functional>
#include <iterator>
#include <boost/container_hash/detail/hash_float.hpp>
#include <string>
#include <boost/limits.hpp>
@@ -426,7 +427,7 @@ namespace boost
for(; first != last; ++first)
{
hash_combine(seed, *first);
hash_combine<typename std::iterator_traits<It>::value_type>(seed, *first);
}
return seed;
@@ -437,7 +438,7 @@ namespace boost
{
for(; first != last; ++first)
{
hash_combine(seed, *first);
hash_combine<typename std::iterator_traits<It>::value_type>(seed, *first);
}
}