2 // Copyright 2005-2009 Daniel James.
3 // Distributed under the Boost Software License, Version 1.0. (See accompanying
4 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 // Based on Peter Dimov's proposal
7 // http://www.open-std.org/JTC1/SC22/WG21/docs/papers/2005/n1756.pdf
10 #if !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
11 #define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
13 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
20 #if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
23 template <bool IsArray
>
29 static std::size_t call(T
const& v
)
31 using namespace boost
;
38 struct call_hash_impl
<true>
40 template <class Array
>
43 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
44 static std::size_t call(Array
const& v
)
46 static std::size_t call(Array
& v
)
49 const int size
= sizeof(v
) / sizeof(*v
);
50 return boost::hash_range(v
, v
+ size
);
57 : public call_hash_impl
<boost::is_array
<T
>::value
>
58 ::BOOST_NESTED_TEMPLATE inner
<T
>
62 #endif // BOOST_NO_FUNCTION_TEMPLATE_ORDERING
64 #if !defined(BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION)
66 template <class T
> struct hash
67 : std::unary_function
<T
, std::size_t>
69 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
70 std::size_t operator()(T
const& val
) const
72 return hash_value(val
);
75 std::size_t operator()(T
const& val
) const
77 return hash_detail::call_hash
<T
>::call(val
);
82 #if BOOST_WORKAROUND(__DMC__, <= 0x848)
83 template <class T
, unsigned int n
> struct hash
<T
[n
]>
84 : std::unary_function
<T
[n
], std::size_t>
86 std::size_t operator()(const T
* val
) const
88 return boost::hash_range(val
, val
+n
);
93 #else // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
95 // On compilers without partial specialization, boost::hash<T>
96 // has already been declared to deal with pointers, so just
97 // need to supply the non-pointer version.
101 template <bool IsPointer
>
104 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
107 struct hash_impl
<false>
111 : std::unary_function
<T
, std::size_t>
113 #if !defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
114 std::size_t operator()(T
const& val
) const
116 return hash_value(val
);
119 std::size_t operator()(T
const& val
) const
121 return hash_detail::call_hash
<T
>::call(val
);
127 #else // Visual C++ 6.5
129 // There's probably a more elegant way to Visual C++ 6.5 to work
130 // but I don't know what it is.
132 template <bool IsConst
>
133 struct hash_impl_msvc
137 : public std::unary_function
<T
, std::size_t>
139 std::size_t operator()(T
const& val
) const
141 return hash_detail::call_hash
<T
const>::call(val
);
144 std::size_t operator()(T
& val
) const
146 return hash_detail::call_hash
<T
>::call(val
);
152 struct hash_impl_msvc
<true>
156 : public std::unary_function
<T
, std::size_t>
158 std::size_t operator()(T
& val
) const
160 return hash_detail::call_hash
<T
>::call(val
);
166 struct hash_impl_msvc2
167 : public hash_impl_msvc
<boost::is_const
<T
>::value
>
168 ::BOOST_NESTED_TEMPLATE inner
<T
> {};
171 struct hash_impl
<false>
174 struct inner
: public hash_impl_msvc2
<T
> {};
177 #endif // Visual C++ 6.5
179 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION