fix doc example typo
[boost.git] / boost / functional / hash / extensions.hpp
blobd173314d7e9df39f6c683282868ff90d07f61a8e
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
8 // issue 6.18.
10 #if !defined(BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP)
11 #define BOOST_FUNCTIONAL_HASH_EXTENSIONS_HPP
13 #if defined(_MSC_VER) && (_MSC_VER >= 1020)
14 # pragma once
15 #endif
17 namespace boost
20 #if defined(BOOST_NO_FUNCTION_TEMPLATE_ORDERING)
21 namespace hash_detail
23 template <bool IsArray>
24 struct call_hash_impl
26 template <class T>
27 struct inner
29 static std::size_t call(T const& v)
31 using namespace boost;
32 return hash_value(v);
37 template <>
38 struct call_hash_impl<true>
40 template <class Array>
41 struct inner
43 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
44 static std::size_t call(Array const& v)
45 #else
46 static std::size_t call(Array& v)
47 #endif
49 const int size = sizeof(v) / sizeof(*v);
50 return boost::hash_range(v, v + size);
55 template <class T>
56 struct call_hash
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);
74 #else
75 std::size_t operator()(T const& val) const
77 return hash_detail::call_hash<T>::call(val);
79 #endif
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);
91 #endif
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.
99 namespace hash_detail
101 template <bool IsPointer>
102 struct hash_impl;
104 #if !BOOST_WORKAROUND(BOOST_MSVC, < 1300)
106 template <>
107 struct hash_impl<false>
109 template <class T>
110 struct inner
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);
118 #else
119 std::size_t operator()(T const& val) const
121 return hash_detail::call_hash<T>::call(val);
123 #endif
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
135 template <class T>
136 struct inner
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);
151 template <>
152 struct hash_impl_msvc<true>
154 template <class T>
155 struct inner
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);
165 template <class T>
166 struct hash_impl_msvc2
167 : public hash_impl_msvc<boost::is_const<T>::value>
168 ::BOOST_NESTED_TEMPLATE inner<T> {};
170 template <>
171 struct hash_impl<false>
173 template <class T>
174 struct inner : public hash_impl_msvc2<T> {};
177 #endif // Visual C++ 6.5
179 #endif // BOOST_NO_TEMPLATE_PARTIAL_SPECIALIZATION
182 #endif