AnySet Documentation
AnyHash.h
1 #ifndef ANY_HASH_H
2 #define ANY_HASH_H
3 
4 #ifdef _MSC_VER
5 # include <iso646.h>
6 #endif
7 
8 #include <functional>
9 #include <cstddef>
10 #include <type_traits>
11 
12 namespace te {
13 
24 template <class T = void>
25 struct Hash: std::hash<T>
26 {
27 
28 };
29 
30 namespace detail {
31 
32 template <class T>
34  std::conditional_t<
35  std::is_default_constructible_v<Hash<T>>,
36  std::true_type,
37  std::false_type
38  >
39 {
40 
41 };
42 
43 template <class T>
44 inline constexpr const bool has_hash_specialization_v = has_hash_specialization<T>::value;
45 
46 } /* namespace detail */
47 
48 
49 
54 template <>
55 struct Hash<void>
56 {
62  template <class T>
63  std::size_t operator()(const T& value) const
64  { return std::invoke(Hash<T>{}, value); }
65 };
66 
94 template <class T, class = std::enable_if_t<detail::has_hash_specialization_v<T>>>
95 std::size_t hash_value(const T& value)
96 { return std::invoke(Hash<T>{}, value); }
97 
107 struct AnyHash {
108 
125  template <class T>
126  std::size_t operator()(const T& value) const
127  {
128  using te::hash_value;
129  return hash_value(value);
130  }
131 };
132 
133 } /* namespace te */
134 
135 #endif /* ANY_HASH_H */
std::size_t operator()(const T &value) const
Generic hash function.
Definition: AnyHash.h:63
Definition: AnyHash.h:33
Primary classes and utility functions for AnySet.
Definition: SetOperations.h:21
Generic hash function object.
Definition: AnyHash.h:107
std::size_t hash_value(const T &value)
Generic hash function.
Definition: AnyHash.h:95
Function object that implements a hash function for instances of type T. Inherits from std::hash<T> u...
Definition: AnyHash.h:25
std::size_t operator()(const T &value) const
Implements a generic hash function.
Definition: AnyHash.h:126