1
#ifndef CHILON_HASH_HPP
2
#define CHILON_HASH_HPP
3
4
#include <boost/functional/hash.hpp>
5
6
#include <vector>
7
#include <type_traits>
8
9
namespace chilon {
10
11
namespace detail {
12
    struct hashable {};
13
14
    template <class T, bool Custom>
15
    struct hasher : T::hash_type {};
16
17
    template <class T>
18
    struct hasher<T, false> : std::hash<T> {};
19
}
20
21
template <class T>
22
struct hasher
23
  : detail::hasher<T, std::is_base_of<detail::hashable, T>::value> {};
24
25
template <class T>
26
struct hasher< std::vector<T> > {
27
    size_t operator()(std::vector<T> const& t) const {
28
        return boost::hash_range(t.begin(), t.end());
29
    }
30
};
31
32
template <class T>
33
size_t hash(T const& t) {
34
    return hasher<T>()(t);
35
}
36
37
template <class H>
38
struct hashable : detail::hashable {
39
    typedef H hash_type;
40
};
41
42
}
43
#endif