25 #ifndef LUNCHBOX_STDEXT_H
26 #define LUNCHBOX_STDEXT_H
28 #include <lunchbox/compiler.h>
29 #include <lunchbox/uint128_t.h>
30 #include <lunchbox/uuid.h>
35 #ifdef LB_GCC_4_4_OR_LATER
36 # include <parallel/algorithm>
41 # if defined LB_GCC_4_3_OR_LATER && !defined __INTEL_COMPILER
42 # define LB_STDEXT_TR1
43 # elif defined __clang__
44 # define LB_STDEXT_TR1
46 # define LB_STDEXT_EXT
48 #elif defined _MSC_VER
49 # define LB_STDEXT_MSVC
51 # define LB_STDEXT_TR1
52 # define LB_STDEXT_TR1_BOOST
54 # define LB_STDEXT_STD
58 # ifdef LB_STDEXT_TR1_BOOST
59 # include <boost/tr1/functional.hpp>
60 # include <boost/tr1/unordered_map.hpp>
61 # include <boost/tr1/unordered_set.hpp>
63 # include <tr1/unordered_map>
64 # include <tr1/unordered_set>
67 namespace stde = std::tr1;
68 # define LB_STDEXT_NAMESPACE_OPEN namespace std { namespace tr1 {
69 # define LB_STDEXT_NAMESPACE_CLOSE }}
73 # include <ext/hash_map>
74 # include <ext/hash_set>
76 namespace stde = __gnu_cxx;
77 # define LB_STDEXT_NAMESPACE_OPEN namespace __gnu_cxx {
78 # define LB_STDEXT_NAMESPACE_CLOSE }
85 namespace stde = stdext;
86 # define LB_STDEXT_NAMESPACE_OPEN namespace stdext {
87 # define LB_STDEXT_NAMESPACE_CLOSE }
95 # define LB_STDEXT_NAMESPACE_OPEN namespace std {
96 # define LB_STDEXT_NAMESPACE_CLOSE }
100 LB_STDEXT_NAMESPACE_OPEN
104 # ifndef LB_HAVE_HASH_MAP
105 template<
class K,
class T,
class H = hash< K >,
106 class P = std::equal_to< K >,
class A = std::allocator< K > >
107 class hash_map :
public unordered_map< K, T, H, P, A >
110 # endif // LB_HAVE_HASH_MAP
111 # ifndef LB_HAVE_HASH_SET
112 template<
class T,
class H = hash< T >,
113 class P = std::equal_to< T >,
class A = std::allocator< T > >
114 class hash_set :
public unordered_set< T, H, P, A >
117 # endif // LB_HAVE_HASH_SET
121 # ifndef LB_HAVE_STRING_HASH
123 template<>
struct hash< std::string >
125 size_t operator()(
const std::string& str )
const
127 return hash< const char* >()( str.c_str() );
130 # endif // LB_HAVE_STRING_HASH
132 # if !defined __INTEL_COMPILER
133 # ifndef LB_HAVE_LONG_HASH
135 template<>
struct hash< uint64_t >
137 size_t operator()(
const uint64_t& val )
const
141 return static_cast< size_t >( val );
145 # endif // !__INTEL_COMPILER
147 # ifndef LB_HAVE_VOID_PTR_HASH
149 template<>
struct hash< void* >
151 template<
typename P >
152 size_t operator()(
const P& key )
const
154 return reinterpret_cast<size_t>(key);
158 template<>
struct hash< const void* >
160 template<
typename P >
161 size_t operator()(
const P& key )
const
163 return reinterpret_cast<size_t>(key);
166 # endif // LB_HAVE_VOID_PTR_HASH
167 #endif // LB_STDEXT_EXT
169 #ifdef LB_STDEXT_MSVC
170 # ifndef LB_HAVE_STRING_HASH
173 template<>
inline size_t hash_compare< std::string >::operator()
174 (
const std::string& key )
const
176 return hash_value( key.c_str( ));
181 template<>
inline size_t hash_compare< lunchbox::uint128_t >::operator()
184 return static_cast< size_t >( key.high() ^ key.low() );
189 return static_cast< size_t >( key.
high() ^ key.
low() );
192 template<>
inline size_t hash_compare< lunchbox::UUID >::operator()
195 return static_cast< size_t >( key.
high() ^ key.
low() );
200 return static_cast< size_t >( key.
high() ^ key.
low() );
206 template<>
struct hash< lunchbox::uint128_t >
215 template<>
struct hash< lunchbox::UUID >
229 template<
typename C >
void usort( C& c )
231 std::sort( c.begin(), c.end( ));
232 c.erase( std::unique( c.begin(), c.end( )), c.end( ));
236 #ifdef LB_GCC_4_4_OR_LATER
237 using __gnu_parallel::sort;
243 template<
typename T >
typename std::vector< T >::iterator
244 find( std::vector< T >& container,
const T& element )
245 {
return std::find( container.begin(), container.end(), element ); }
248 template<
typename T >
typename std::vector< T >::const_iterator
249 find(
const std::vector< T >& container,
const T& element )
250 {
return std::find( container.begin(), container.end(), element ); }
253 template<
typename T,
typename P >
typename std::vector< T >::iterator
254 find_if( std::vector< T >& container,
const P& predicate )
255 {
return std::find_if( container.begin(), container.end(), predicate );}
258 template<
typename T,
typename P >
typename std::vector<T>::const_iterator
259 find_if( std::vector< const T >& container,
const P& predicate )
260 {
return std::find_if( container.begin(), container.end(), predicate );}
262 LB_STDEXT_NAMESPACE_CLOSE
264 #endif // LUNCHBOX_STDEXT_H