diff options
Diffstat (limited to 'src/google/protobuf/stubs/hash.h')
-rw-r--r-- | src/google/protobuf/stubs/hash.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/google/protobuf/stubs/hash.h b/src/google/protobuf/stubs/hash.h index be998b29..fd8ba156 100644 --- a/src/google/protobuf/stubs/hash.h +++ b/src/google/protobuf/stubs/hash.h @@ -40,10 +40,9 @@ #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 -#define GOOGLE_PROTOBUF_HAVE_64BIT_HASH 1 // Use C++11 unordered_{map|set} if available. -#if ((_LIBCPP_STD_VER >= 11) || \ +#if ((defined(_LIBCPP_STD_VER) && _LIBCPP_STD_VER >= 11) || \ (((__cplusplus >= 201103L) || defined(__GXX_EXPERIMENTAL_CXX0X)) && \ (__GLIBCXX__ > 20090421))) # define GOOGLE_PROTOBUF_HAS_CXX11_HASH @@ -93,8 +92,11 @@ # define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set # endif -# if __GNUC__ == 4 && __GNUC__MINOR__ <= 1 -# undef GOOGLE_PROTOBUF_HAVE_64BIT_HASH +// GCC <= 4.1 does not define std::tr1::hash for `long long int` or `long long unsigned int` +# if __GNUC__ == 4 && defined(__GNUC_MINOR__) && __GNUC_MINOR__ <= 1 +# undef GOOGLE_PROTOBUF_HAS_TR1 +# undef GOOGLE_PROTOBUF_HAVE_HASH_MAP +# undef GOOGLE_PROTOBUF_HAVE_HASH_SET # endif // Version checks for MSC. @@ -233,7 +235,8 @@ class hash_set : public std::set<Key, HashFcn> { HashFcn hash_function() const { return HashFcn(); } }; -#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) +#elif defined(_MSC_VER) && !defined(_STLPORT_VERSION) && \ + !(defined(_LIBCPP_STD_VER) && _LIBCPP_STD_VER >= 11) template <typename Key> struct hash : public GOOGLE_PROTOBUF_HASH_COMPARE<Key> { @@ -348,7 +351,7 @@ struct hash<const char*> { inline size_t operator()(const char* str) const { size_t result = 0; for (; *str != '\0'; str++) { - result = 5 * result + *str; + result = 5 * result + static_cast<size_t>(*str); } return result; } @@ -406,8 +409,8 @@ struct hash<string> { }; template <typename First, typename Second> -struct hash<pair<First, Second> > { - inline size_t operator()(const pair<First, Second>& key) const { +struct hash<std::pair<First, Second> > { + inline size_t operator()(const std::pair<First, Second>& key) const { size_t first_hash = hash<First>()(key.first); size_t second_hash = hash<Second>()(key.second); @@ -418,8 +421,8 @@ struct hash<pair<First, Second> > { static const size_t bucket_size = 4; static const size_t min_buckets = 8; - inline bool operator()(const pair<First, Second>& a, - const pair<First, Second>& b) const { + inline bool operator()(const std::pair<First, Second>& a, + const std::pair<First, Second>& b) const { return a < b; } }; |