16 #ifndef INCLUDE_NN_NLIB_HASH_H_ 17 #define INCLUDE_NN_NLIB_HASH_H_ 22 #if defined(__cpp_alias_templates) 24 template<
class T>
using Hash = std::hash<T>;
26 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) namespace std { // NOLINT 27 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) namespace std { // NOLINT 28 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) namespace std { // NOLINT 29 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) } // NOLINT 30 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) } // NOLINT 31 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) } // NOLINT 32 #define NLIB_DEFINE_STD_HASH_T(tp) \ 33 template<> struct hash<tp> { \ 34 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 36 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 37 template<class targ1, class targ2> struct hash<tp<targ1, targ2> > { \ 38 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 45 inline size_t Times33(
const unsigned char* p,
size_t n)
NLIB_NOEXCEPT {
47 for (; n != 0; --n, ++p) { hash = hash * 33 + *p; }
53 struct SimpleHash :
public std::unary_function<T, size_t> {
55 return detail::Times33(
56 reinterpret_cast<const unsigned char*>(&val),
sizeof(val));
60 template<
class T>
struct Hash :
public SimpleHash<T> {};
62 template<>
struct Hash<bool> :
public SimpleHash<bool> {};
63 template<>
struct Hash<char> :
public SimpleHash<char> {};
64 template<>
struct Hash<signed char> :
public SimpleHash<signed char> {};
65 template<>
struct Hash<unsigned char> :
public SimpleHash<unsigned char> {};
66 template<>
struct Hash<wchar_t> :
public SimpleHash<wchar_t> {};
67 template<>
struct Hash<short> :
public SimpleHash<short> {};
68 template<>
struct Hash<unsigned short> :
public SimpleHash<unsigned short> {};
69 template<>
struct Hash<int> :
public SimpleHash<int> {};
70 template<>
struct Hash<unsigned int> :
public SimpleHash<unsigned int> {};
71 template<>
struct Hash<long> :
public SimpleHash<long> {};
72 template<>
struct Hash<unsigned long> :
public SimpleHash<unsigned long> {};
73 template<>
struct Hash<long long> :
public SimpleHash<long long> {};
74 template<>
struct Hash<unsigned long long> :
public SimpleHash<unsigned long long> {};
75 template<>
struct Hash<float> :
public SimpleHash<float> {};
76 template<>
struct Hash<double> :
public SimpleHash<double> {};
77 template<
class T>
struct Hash<T*> :
public SimpleHash<T*> {};
82 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) NLIB_NAMESPACE_BEGIN // NOLINT 83 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) \ 84 NLIB_NAMESPACE_BEGIN namespace ns3 { // NOLINT 85 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) \ 86 NLIB_NAMESPACE_BEGIN namespace ns3 { namespace ns4 { // NOLINT 87 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) NLIB_NAMESPACE_END // NOLINT 88 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) } NLIB_NAMESPACE_END // NOLINT 89 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) }} NLIB_NAMESPACE_END // NOLINT 91 #define NLIB_DEFINE_STD_HASH_T(tp) \ 92 template<> struct Hash<tp> { \ 93 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 95 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 96 template<class targ1, class targ2> struct Hash<tp<targ1, targ2> > { \ 97 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 106 #endif // INCLUDE_NN_NLIB_HASH_H_ #define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。