Commit 4065a316 authored by Jisi Liu's avatar Jisi Liu

Fix hash.h for MSVC and platforms without hash map/set support.

Change-Id: Ic0fdb52c17b9495c73b8ce15879531383a148585
parent 14fe0c99
...@@ -89,16 +89,17 @@ struct hash<const char*> { ...@@ -89,16 +89,17 @@ struct hash<const char*> {
template <typename Key, typename Data, template <typename Key, typename Data,
typename HashFcn = hash<Key>, typename HashFcn = hash<Key>,
typename EqualKey = int, typename EqualKey = std::equal_to<Key>,
typename Alloc = std::allocator< std::pair<const Key, Data> > > typename Alloc = std::allocator< std::pair<const Key, Data> > >
class hash_map : public std::map<Key, Data, HashFcn, Alloc> { class hash_map : public std::map<Key, Data, HashFcn, EqualKey, Alloc> {
public: public:
hash_map(int = 0) {} hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(),
const Alloc& = Alloc()) {}
}; };
template <typename Key, template <typename Key,
typename HashFcn = hash<Key>, typename HashFcn = hash<Key>,
typename EqualKey = int > typename EqualKey = std::equal_to<Key> >
class hash_set : public std::set<Key, HashFcn> { class hash_set : public std::set<Key, HashFcn> {
public: public:
hash_set(int = 0) {} hash_set(int = 0) {}
...@@ -126,19 +127,21 @@ struct hash<const char*> ...@@ -126,19 +127,21 @@ struct hash<const char*>
template <typename Key, typename Data, template <typename Key, typename Data,
typename HashFcn = hash<Key>, typename HashFcn = hash<Key>,
typename EqualKey = int, typename EqualKey = std::equal_to<Key>,
typename Alloc = std::allocator< std::pair<const Key, Data> > > typename Alloc = std::allocator< std::pair<const Key, Data> > >
class hash_map : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_map< class hash_map
Key, Data, HashFcn, Alloc> { : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_MAP_CLASS<
Key, Data, HashFcn, EqualKey, Alloc> {
public: public:
hash_map(int = 0) {} hash_map(int = 0, const HashFcn& = HashFcn(), const EqualKey& = EqualKey(),
const Alloc& = Alloc()) {}
}; };
template <typename Key, template <typename Key, typename HashFcn = hash<Key>,
typename HashFcn = hash<Key>, typename EqualKey = std::equal_to<Key> >
typename EqualKey = int > class hash_set
class hash_set : public GOOGLE_PROTOBUF_HASH_NAMESPACE::hash_set< : public GOOGLE_PROTOBUF_HASH_NAMESPACE::GOOGLE_PROTOBUF_HASH_SET_CLASS<
Key, HashFcn> { Key, HashFcn, EqualKey> {
public: public:
hash_set(int = 0) {} hash_set(int = 0) {}
}; };
...@@ -169,7 +172,8 @@ struct hash<const char*> { ...@@ -169,7 +172,8 @@ struct hash<const char*> {
} }
}; };
template <typename Key, typename Data, typename HashFcn = hash<Key>, template <typename Key, typename Data,
typename HashFcn = hash<Key>,
typename EqualKey = std::equal_to<Key>, typename EqualKey = std::equal_to<Key>,
typename Alloc = std::allocator< std::pair<const Key, Data> > > typename Alloc = std::allocator< std::pair<const Key, Data> > >
class hash_map class hash_map
......
/* protobuf config.h for MSVC. On other platforms, this is generated /* protobuf config.h for MSVC. On other platforms, this is generated
* automatically by autoheader / autoconf / configure. */ * automatically by autoheader / autoconf / configure. */
/* the location of <hash_map> */ #include <google/protobuf/stubs/pbconfig.h>
#define HASH_MAP_H <hash_map>
/* the namespace of hash_map/hash_set */ #define HASH_MAP_H GOOGLE_PROTOBUF_HASH_MAP_H
// Apparently Microsoft decided to move hash_map *back* to the std namespace #define HASH_NAMESPACE GOOGLE_PROTOBUF_HASH_NAMESPACE
// in MSVC 2010: #define HASH_SET_H GOOGLE_PROTOBUF_HASH_SET_H
// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx
// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010.
#if _MSC_VER < 1310 || _MSC_VER >= 1600
#define HASH_NAMESPACE std
#else
#define HASH_NAMESPACE stdext
#endif
/* the location of <hash_set> */
#define HASH_SET_H <hash_set>
/* define if the compiler has hash_map */ #ifdef GOOGLE_PROTOBUF_HAVE_HASH_MAP
#define HAVE_HASH_MAP 1 #define HAVE_HASH_MAP GOOGLE_PROTOBUF_HAVE_HASH_MAP
#endif
/* define if the compiler has hash_set */ #ifdef GOOGLE_PROTOBUF_HAVE_HASH_SET
#define HAVE_HASH_SET 1 #define HAVE_HASH_SET GOOGLE_PROTOBUF_HAVE_HASH_SET
#endif
/* define if you want to use zlib. See readme.txt for additional /* define if you want to use zlib. See readme.txt for additional
* requirements. */ * requirements. */
......
/* protobuf config.h for MSVC. On other platforms, this is generated /* protobuf config.h for MSVC. On other platforms, this is generated
* automatically by autoheader / autoconf / configure. */ * automatically by autoheader / autoconf / configure. */
/* the location of <hash_map> */ // NOTE: if you add new macros in this file manually, please propagate the macro
#define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map> // to vsprojects/config.h.
/* the namespace of hash_map/hash_set */ /* the namespace of hash_map/hash_set */
// Apparently Microsoft decided to move hash_map *back* to the std namespace // Apparently Microsoft decided to move hash_map *back* to the std namespace
// in MSVC 2010: // in MSVC 2010:
// http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx // http://blogs.msdn.com/vcblog/archive/2009/05/25/stl-breaking-changes-in-visual-studio-2010-beta-1.aspx
// TODO(kenton): Use unordered_map instead, which is available in MSVC 2010. // And.. they are moved back to stdext in MSVC 2013 (haven't checked 2012). That
#if _MSC_VER < 1310 || _MSC_VER >= 1600 // said, use unordered_map for MSVC 2010 and beyond is our safest bet.
#if _MSC_VER >= 1600
#define GOOGLE_PROTOBUF_HASH_NAMESPACE std #define GOOGLE_PROTOBUF_HASH_NAMESPACE std
#else #define GOOGLE_PROTOBUF_HASH_MAP_H <unordered_map>
#define GOOGLE_PROTOBUF_HASH_MAP_CLASS unordered_map
#define GOOGLE_PROTOBUF_HASH_SET_H <unordered_set>
#define GOOGLE_PROTOBUF_HASH_SET_CLASS unordered_set
#elif _MSC_VER >= 1310
#define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext #define GOOGLE_PROTOBUF_HASH_NAMESPACE stdext
#define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map>
#define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
#define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
#define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
#else
#define GOOGLE_PROTOBUF_HASH_NAMESPACE std
#define GOOGLE_PROTOBUF_HASH_MAP_H <hash_map>
#define GOOGLE_PROTOBUF_HASH_MAP_CLASS hash_map
#define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
#define GOOGLE_PROTOBUF_HASH_SET_CLASS hash_set
#endif #endif
/* the location of <hash_set> */ /* the location of <hash_set> */
#define GOOGLE_PROTOBUF_HASH_SET_H <hash_set>
/* define if the compiler has hash_map */ /* define if the compiler has hash_map */
#define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1 #define GOOGLE_PROTOBUF_HAVE_HASH_MAP 1
/* define if the compiler has hash_set */ /* define if the compiler has hash_set */
#define GOOGLE_PROTOBUF_HAVE_HASH_SET 1 #define GOOGLE_PROTOBUF_HAVE_HASH_SET 1
/* define if you want to use zlib. See readme.txt for additional
* requirements. */
// #define HAVE_ZLIB 1
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment