stdExt.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00024 #ifndef EQBASE_STDEXT_H
00025 #define EQBASE_STDEXT_H
00026
00027 #include <algorithm>
00028 #include <string>
00029
00030
00031 #ifdef __GNUC__ // GCC 3.1 and later
00032 # include <ext/hash_map>
00033 # include <ext/hash_set>
00034
00035 namespace stde = __gnu_cxx;
00036 #else // other compilers
00037 # include <hash_map>
00038 # include <hash_set>
00039 # ifdef WIN32
00040
00041 namespace stde = stdext;
00042 # else
00043
00044 namespace stde = std;
00045 # endif
00046 #endif
00047
00048
00049
00050 #ifdef __GNUC__ // GCC 3.1 and later
00051 namespace __gnu_cxx
00052 #elif defined (WIN32)
00053 namespace stdext
00054 #else
00055 namespace std
00056 #endif
00057 {
00058 # ifdef __GNUC__
00059 # ifndef EQ_HAVE_STRING_HASH
00060
00061 template<>
00062 struct hash< std::string >
00063 {
00064 size_t operator()( const std::string& str ) const
00065 {
00066 return hash< const char* >()( str.c_str() );
00067 }
00068 };
00069 # endif
00070
00071 # ifndef EQ_HAVE_VOID_PTR_HASH
00072
00073 template<>
00074 struct hash< void* >
00075 {
00076 template< typename P >
00077 size_t operator()( const P& key ) const
00078 {
00079 return reinterpret_cast<size_t>(key);
00080 }
00081 };
00082 template<>
00083 struct hash< const void* >
00084 {
00085 template< typename P >
00086 size_t operator()( const P& key ) const
00087 {
00088 return reinterpret_cast<size_t>(key);
00089 }
00090 };
00091 # endif
00092
00093 # else // WIN32
00094 # ifndef EQ_HAVE_STRING_HASH
00095
00097 template<>
00098 inline size_t hash_compare< std::string >::operator()
00099 ( const std::string& key ) const
00100 {
00101 return hash_value( key.c_str( ));
00102 }
00103
00104 # endif
00105 # endif
00106
00108 template< typename C >
00109 void usort( C& c )
00110 {
00111 std::sort( c.begin(), c.end( ));
00112 c.erase( std::unique( c.begin(), c.end( )), c.end( ));
00113 }
00114 }
00115
00116 #endif // EQBASE_STDEXT_H