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