add hash function for CGAL vector container

This commit is contained in:
Sébastien Loriot 2022-02-24 11:34:31 +01:00
parent 622e724e87
commit 697e1abbc9
2 changed files with 38 additions and 7 deletions

View File

@ -27,7 +27,6 @@
#include <functional>
#include <algorithm>
#include <CGAL/memory.h>
#include <boost/functional/hash.hpp>
namespace CGAL {
@ -175,7 +174,6 @@ namespace internal {
};
template <class T, class Alloc>
std::size_t hash_value(const In_place_list_iterator<T,Alloc>& i)
{
@ -189,7 +187,7 @@ template <class T, class Alloc>
{
const T* ptr = i.operator->();
return reinterpret_cast<std::size_t>(ptr)/ sizeof(T);
}
}
}
@ -792,8 +790,7 @@ namespace std {
std::size_t operator()(const CGAL::internal::In_place_list_iterator<T, Alloc>& i) const
{
const T* ptr = i.operator->();
return reinterpret_cast<std::size_t>(ptr)/ sizeof(T);
return CGAL::internal::hash_value(i);
}
};
@ -803,8 +800,7 @@ namespace std {
std::size_t operator()(const CGAL::internal::In_place_list_const_iterator<T, Alloc>& i) const
{
const T* ptr =i.operator->();
return reinterpret_cast<std::size_t>(ptr)/ sizeof(T);
return CGAL::internal::hash_value(i);
}
};
#endif // CGAL_CFG_NO_STD_HASH

View File

@ -24,6 +24,7 @@
#include <algorithm>
#include <memory>
#include <cstddef>
#include <functional>
#include <boost/type_traits/remove_const.hpp>
#include <boost/type_traits/remove_reference.hpp>
#include <boost/type_traits/remove_pointer.hpp>
@ -135,6 +136,13 @@ public:
}
};
template < class T, class Ref, class Ptr>
std::size_t hash_value(const vector_iterator<T, Ref, Ptr>& i)
{
Ptr ptr = i.operator->();
return reinterpret_cast<std::size_t>(ptr)/ sizeof(T);
}
template < class T, class Ref, class Ptr> inline
vector_iterator<T,Ref,Ptr>
operator+( std::ptrdiff_t n, vector_iterator<T,Ref,Ptr> i) {
@ -609,4 +617,31 @@ void vector<T, Alloc>::insert( iterator position, size_type n, const T& x) {
} //namespace CGAL
namespace std {
#if defined(BOOST_MSVC)
# pragma warning(push)
# pragma warning(disable:4099) // For VC10 it is class hash
#endif
#ifndef CGAL_CFG_NO_STD_HASH
template < class T, class Ref, class Ptr>
struct hash<CGAL::internal::vector_iterator<T, Ref, Ptr> >
: public CGAL::cpp98::unary_function<CGAL::internal::vector_iterator<T, Ref, Ptr>, std::size_t> {
std::size_t operator()(const CGAL::internal::vector_iterator<T, Ref, Ptr>& i) const
{
return CGAL::internal::hash_value(i);
}
};
#endif // CGAL_CFG_NO_STD_HASH
#if defined(BOOST_MSVC)
# pragma warning(pop)
#endif
} // namespace std
#endif // CGAL_VECTOR_H //