26 #ifndef LUNCHBOX_STDEXT_H
27 #define LUNCHBOX_STDEXT_H
29 #include <lunchbox/algorithm.h>
30 #include <lunchbox/compiler.h>
31 #ifdef LUNCHBOX_USE_V1_API
32 # include <lunchbox/uint128_t.h>
34 # include <servus/uint128_t.h>
37 #include <boost/config.hpp>
41 #ifdef LB_USE_STD_PARALLEL
42 # include <parallel/algorithm>
46 #ifdef BOOST_NO_STD_UNORDERED
48 # if defined LB_GCC_4_3_OR_LATER && !defined __INTEL_COMPILER
49 # define LB_STDEXT_TR1
50 # elif defined __clang__
51 # define LB_STDEXT_TR1
53 # define LB_STDEXT_EXT
55 # elif defined _MSC_VER
56 # define LB_STDEXT_MSVC
57 # elif defined __xlC__
58 # define LB_STDEXT_TR1
59 # define LB_STDEXT_TR1_BOOST
61 # define LB_STDEXT_STD
64 # define LB_STDEXT_STD
65 # define LB_STDEXT_STD11
69 # ifdef LB_STDEXT_TR1_BOOST
70 # include <boost/tr1/functional.hpp>
71 # include <boost/tr1/unordered_map.hpp>
72 # include <boost/tr1/unordered_set.hpp>
74 # include <tr1/unordered_map>
75 # include <tr1/unordered_set>
78 namespace stde = std::tr1;
79 # define LB_STDEXT_NAMESPACE_OPEN namespace std { namespace tr1 {
80 # define LB_STDEXT_NAMESPACE_CLOSE }}
84 # include <ext/hash_map>
85 # include <ext/hash_set>
87 namespace stde = __gnu_cxx;
88 # define LB_STDEXT_NAMESPACE_OPEN namespace __gnu_cxx {
89 # define LB_STDEXT_NAMESPACE_CLOSE }
96 namespace stde = stdext;
97 # define LB_STDEXT_NAMESPACE_OPEN namespace stdext {
98 # define LB_STDEXT_NAMESPACE_CLOSE }
102 # ifdef LB_STDEXT_STD11
103 # include <unordered_map>
104 # include <unordered_set>
111 # define LB_STDEXT_NAMESPACE_OPEN namespace std {
112 # define LB_STDEXT_NAMESPACE_CLOSE }
116 LB_STDEXT_NAMESPACE_OPEN
119 #if defined LB_STDEXT_TR1 || defined LB_STDEXT_STD11
120 # ifndef LB_HAVE_HASH_MAP
121 # ifdef CXX_TEMPLATE_ALIAS_SUPPORTED
122 template<
class K,
class T,
class H = hash< K >,
class P = std::equal_to< K >,
123 class A = std::allocator< std::pair< const K, T > > >
124 using hash_map = unordered_map< K, T, H, P, A >;
126 template<
class K,
class T,
class H = hash< K >,
class P = std::equal_to< K >,
127 class A = std::allocator< std::pair< const K, T > > >
128 class hash_map :
public unordered_map< K, T, H, P, A > {};
130 # endif // LB_HAVE_HASH_MAP
131 # ifndef LB_HAVE_HASH_SET
132 # ifdef CXX_TEMPLATE_ALIAS_SUPPORTED
133 template<
class T,
class H = hash< T >,
134 class P = std::equal_to< T >,
class A = std::allocator< T > >
135 using hash_set = unordered_set< T, H, P, A >;
137 template<
class T,
class H = hash< T >,
138 class P = std::equal_to< T >,
class A = std::allocator< T > >
139 class hash_set :
public unordered_set< T, H, P, A > {};
141 # endif // LB_HAVE_HASH_SET
145 # ifndef LB_HAVE_STRING_HASH
147 template<>
struct hash<
std::string >
149 size_t operator()(
const std::string& str )
const
150 {
return hash< const char* >()( str.c_str() ); }
152 # endif // LB_HAVE_STRING_HASH
154 # if !defined __INTEL_COMPILER
155 # ifndef LB_HAVE_LONG_HASH
157 template<>
struct hash< uint64_t >
159 size_t operator()(
const uint64_t& val )
const
163 return static_cast< size_t >( val );
167 # endif // !__INTEL_COMPILER
169 # ifndef LB_HAVE_VOID_PTR_HASH
171 template<>
struct hash< void* >
173 template<
typename P >
size_t operator()(
const P& key )
const
174 {
return reinterpret_cast<size_t>(key); }
177 template<>
struct hash< const void* >
179 template<
typename P >
size_t operator()(
const P& key )
const
180 {
return reinterpret_cast<size_t>(key); }
182 # endif // LB_HAVE_VOID_PTR_HASH
183 #endif // LB_STDEXT_EXT
185 #ifdef LB_STDEXT_MSVC
186 # ifndef LB_HAVE_STRING_HASH
190 size_t hash_compare< std::string >::operator() (
const std::string& key )
const
191 {
return hash_value( key.c_str( )); }
199 #ifndef LB_STDEXT_STD
201 # ifdef LB_GCC_4_4_OR_LATER
202 using __gnu_parallel::sort;
208 LB_STDEXT_NAMESPACE_CLOSE
211 #endif // LUNCHBOX_STDEXT_H
void usort(C &c)
Uniquely sort and eliminate duplicates in a container.