3 #ifndef INCLUDE_NN_NLIB_HASH_H_ 4 #define INCLUDE_NN_NLIB_HASH_H_ 9 #if defined(NLIB_CXX11_TEMPLATE_ALIAS) 11 template<
class T>
using Hash = std::hash<T>;
13 #define NLIB_DEFINE_STD_HASH_BEGIN1(ns1) namespace std { // NOLINT 14 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) namespace std { // NOLINT 15 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) namespace std { // NOLINT 16 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) namespace std { // NOLINT 17 #define NLIB_DEFINE_STD_HASH_END1(ns1) } // NOLINT 18 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) } // NOLINT 19 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) } // NOLINT 20 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) } // NOLINT 21 #define NLIB_DEFINE_STD_HASH_T(tp) \ 22 template<> struct hash<tp> { \ 23 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 25 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 26 template<class targ1, class targ2> struct hash<tp<targ1, targ2> > { \ 27 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 34 inline size_t Times33(
const unsigned char* p,
size_t n)
NLIB_NOEXCEPT {
36 for (; n != 0; --n, ++p) { hash = hash * 33 + *p; }
42 struct SimpleHash :
public std::unary_function<T, size_t> {
44 return detail::Times33(
45 reinterpret_cast<const unsigned char*>(&val),
sizeof(val));
49 template<
class T>
struct Hash :
public SimpleHash<T> {};
51 template<>
struct Hash<bool> :
public SimpleHash<bool> {};
52 template<>
struct Hash<char> :
public SimpleHash<char> {};
53 template<>
struct Hash<signed char> :
public SimpleHash<signed char> {};
54 template<>
struct Hash<unsigned char> :
public SimpleHash<unsigned char> {};
55 template<>
struct Hash<wchar_t> :
public SimpleHash<wchar_t> {};
56 template<>
struct Hash<short> :
public SimpleHash<short> {};
57 template<>
struct Hash<unsigned short> :
public SimpleHash<unsigned short> {};
58 template<>
struct Hash<int> :
public SimpleHash<int> {};
59 template<>
struct Hash<unsigned int> :
public SimpleHash<unsigned int> {};
60 template<>
struct Hash<long> :
public SimpleHash<long> {};
61 template<>
struct Hash<unsigned long> :
public SimpleHash<unsigned long> {};
62 template<>
struct Hash<long long> :
public SimpleHash<long long> {};
63 template<>
struct Hash<unsigned long long> :
public SimpleHash<unsigned long long> {};
64 template<>
struct Hash<float> :
public SimpleHash<float> {};
65 template<>
struct Hash<double> :
public SimpleHash<double> {};
66 template<
class T>
struct Hash<T*> :
public SimpleHash<T*> {};
71 #define NLIB_DEFINE_STD_HASH_BEGIN1(ns1) namespace ns1 { // NOLINT 72 #define NLIB_DEFINE_STD_HASH_BEGIN2(ns1, ns2) namespace ns1 { namespace ns2 { // NOLINT 73 #define NLIB_DEFINE_STD_HASH_BEGIN3(ns1, ns2, ns3) \ 74 namespace ns1 { namespace ns2 { namespace ns3 { // NOLINT 75 #define NLIB_DEFINE_STD_HASH_BEGIN4(ns1, ns2, ns3, ns4) \ 76 namespace ns1 { namespace ns2 { namespace ns3 { namespace ns4 { // NOLINT 77 #define NLIB_DEFINE_STD_HASH_END1(ns1) } // NOLINT 78 #define NLIB_DEFINE_STD_HASH_END2(ns1, ns2) }} // NOLINT 79 #define NLIB_DEFINE_STD_HASH_END3(ns1, ns2, ns3) }}} // NOLINT 80 #define NLIB_DEFINE_STD_HASH_END4(ns1, ns2, ns3, ns4) }}}} // NOLINT 82 #define NLIB_DEFINE_STD_HASH_T(tp) \ 83 template<> struct Hash<tp> { \ 84 size_t operator()(const tp& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 86 #define NLIB_DEFINE_STD_HASH_T2(targ1, targ2, tp) \ 87 template<class targ1, class targ2> struct Hash<tp<targ1, targ2> > { \ 88 size_t operator()(const tp<targ1, targ2>& val) const NLIB_NOEXCEPT { return val.GetHash(); } \ 97 #endif // INCLUDE_NN_NLIB_HASH_H_ #define NLIB_NOEXCEPT
環境に合わせてnoexcept 又は同等の定義がされます。