williamr@2
|
1 |
/*
|
williamr@2
|
2 |
* Copyright (c) 2003
|
williamr@2
|
3 |
* Francois Dumont
|
williamr@2
|
4 |
*
|
williamr@2
|
5 |
* This material is provided "as is", with absolutely no warranty expressed
|
williamr@2
|
6 |
* or implied. Any use is at your own risk.
|
williamr@2
|
7 |
*
|
williamr@2
|
8 |
* Permission to use or copy this software for any purpose is hereby granted
|
williamr@2
|
9 |
* without fee, provided the above notices are retained on all copies.
|
williamr@2
|
10 |
* Permission to modify the code and to distribute modified code is granted,
|
williamr@2
|
11 |
* provided the above notices are retained, and a notice that the code was
|
williamr@2
|
12 |
* modified is included with the above copyright notice.
|
williamr@2
|
13 |
*
|
williamr@2
|
14 |
*/
|
williamr@2
|
15 |
|
williamr@2
|
16 |
/* NOTE: This is an internal header file, included by other STL headers.
|
williamr@2
|
17 |
* You should not attempt to use it directly.
|
williamr@2
|
18 |
*/
|
williamr@2
|
19 |
|
williamr@2
|
20 |
#ifndef _STLP_POINTERS_SPEC_TOOLS_H
|
williamr@2
|
21 |
#define _STLP_POINTERS_SPEC_TOOLS_H
|
williamr@2
|
22 |
|
williamr@2
|
23 |
#ifndef _STLP_TYPE_TRAITS_H
|
williamr@2
|
24 |
# include <stl/type_traits.h>
|
williamr@2
|
25 |
#endif
|
williamr@2
|
26 |
|
williamr@2
|
27 |
_STLP_BEGIN_NAMESPACE
|
williamr@2
|
28 |
|
williamr@2
|
29 |
//Some usefull declarations:
|
williamr@2
|
30 |
template <class _Tp> struct less;
|
williamr@2
|
31 |
|
williamr@2
|
32 |
_STLP_MOVE_TO_PRIV_NAMESPACE
|
williamr@2
|
33 |
|
williamr@2
|
34 |
template <class _StorageT, class _ValueT, class _BinaryPredicate>
|
williamr@2
|
35 |
struct _BinaryPredWrapper;
|
williamr@2
|
36 |
|
williamr@2
|
37 |
/*
|
williamr@2
|
38 |
* Since the compiler only allows at most one non-trivial
|
williamr@2
|
39 |
* implicit conversion we can make use of a shim class to
|
williamr@2
|
40 |
* be sure that functions below doesn't accept classes with
|
williamr@2
|
41 |
* implicit pointer conversion operators
|
williamr@2
|
42 |
*/
|
williamr@2
|
43 |
struct _ConstVolatileVoidPointerShim
|
williamr@2
|
44 |
{ _ConstVolatileVoidPointerShim(const volatile void*); };
|
williamr@2
|
45 |
|
williamr@2
|
46 |
//The dispatch functions:
|
williamr@2
|
47 |
struct _VoidPointerShim
|
williamr@2
|
48 |
{ _VoidPointerShim(void*); };
|
williamr@2
|
49 |
struct _ConstVoidPointerShim
|
williamr@2
|
50 |
{ _ConstVoidPointerShim(const void*); };
|
williamr@2
|
51 |
struct _VolatileVoidPointerShim
|
williamr@2
|
52 |
{ _VolatileVoidPointerShim(volatile void*); };
|
williamr@2
|
53 |
|
williamr@2
|
54 |
template <class _Tp>
|
williamr@2
|
55 |
char _UseVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
|
williamr@2
|
56 |
char _UseVoidPtrStorageType(const __true_type& /*POD*/, ...);
|
williamr@2
|
57 |
char* _UseVoidPtrStorageType(const __true_type& /*POD*/, _VoidPointerShim);
|
williamr@2
|
58 |
|
williamr@2
|
59 |
template <class _Tp>
|
williamr@2
|
60 |
char _UseConstVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
|
williamr@2
|
61 |
char _UseConstVoidPtrStorageType(const __true_type& /*POD*/, ...);
|
williamr@2
|
62 |
char* _UseConstVoidPtrStorageType(const __true_type& /*POD*/, _ConstVoidPointerShim);
|
williamr@2
|
63 |
|
williamr@2
|
64 |
template <class _Tp>
|
williamr@2
|
65 |
char _UseVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
|
williamr@2
|
66 |
char _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
|
williamr@2
|
67 |
char* _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, _VolatileVoidPointerShim);
|
williamr@2
|
68 |
|
williamr@2
|
69 |
template <class _Tp>
|
williamr@2
|
70 |
char _UseConstVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
|
williamr@2
|
71 |
char _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
|
williamr@2
|
72 |
char* _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, _ConstVolatileVoidPointerShim);
|
williamr@2
|
73 |
|
williamr@2
|
74 |
template <class _Tp>
|
williamr@2
|
75 |
struct _StorageType {
|
williamr@2
|
76 |
typedef typename __type_traits<_Tp>::is_POD_type _PODType;
|
williamr@2
|
77 |
static _Tp __null_rep();
|
williamr@2
|
78 |
|
williamr@2
|
79 |
enum { use_void_ptr = (sizeof(_UseVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
|
williamr@2
|
80 |
enum { use_const_void_ptr = (sizeof(_UseConstVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
|
williamr@2
|
81 |
enum { use_volatile_void_ptr = (sizeof(_UseVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
|
williamr@2
|
82 |
enum { use_const_volatile_void_ptr = (sizeof(_UseConstVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
|
williamr@2
|
83 |
|
williamr@2
|
84 |
typedef typename __select<!use_const_volatile_void_ptr,
|
williamr@2
|
85 |
_Tp,
|
williamr@2
|
86 |
typename __select<use_void_ptr,
|
williamr@2
|
87 |
void*,
|
williamr@2
|
88 |
typename __select<use_const_void_ptr,
|
williamr@2
|
89 |
const void*,
|
williamr@2
|
90 |
typename __select<use_volatile_void_ptr,
|
williamr@2
|
91 |
volatile void*,
|
williamr@2
|
92 |
const volatile void*>::_Ret >::_Ret >::_Ret >::_Ret _QualifiedType;
|
williamr@2
|
93 |
|
williamr@2
|
94 |
#if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@2
|
95 |
/* If the compiler do not support the iterator_traits structure we cannot wrap
|
williamr@2
|
96 |
* iterators pass to container template methods. The iterator dereferenced value
|
williamr@2
|
97 |
* has to be storable without any cast in the chosen storage type. To guaranty
|
williamr@2
|
98 |
* that the void pointer has to be correctly qualified.
|
williamr@2
|
99 |
*/
|
williamr@2
|
100 |
typedef _QualifiedType _Type;
|
williamr@2
|
101 |
#else
|
williamr@2
|
102 |
/* With iterator_traits we can wrap passed iterators and make the necessary casts.
|
williamr@2
|
103 |
* We can always use a simple void* storage type:
|
williamr@2
|
104 |
*/
|
williamr@2
|
105 |
typedef typename __select<use_const_volatile_void_ptr,
|
williamr@2
|
106 |
void*,
|
williamr@2
|
107 |
_Tp>::_Ret _Type;
|
williamr@2
|
108 |
#endif
|
williamr@2
|
109 |
};
|
williamr@2
|
110 |
|
williamr@2
|
111 |
template <class _Tp, class _Compare>
|
williamr@2
|
112 |
struct _AssocStorageTypes {
|
williamr@2
|
113 |
typedef _StorageType<_Tp> _StorageTypeInfo;
|
williamr@2
|
114 |
typedef typename _StorageTypeInfo::_Type _SType;
|
williamr@2
|
115 |
|
williamr@2
|
116 |
//We need to also check that the comparison functor used to instanciate the assoc container
|
williamr@2
|
117 |
//is the default Standard less implementation:
|
williamr@2
|
118 |
typedef typename _IsSTLportClass<_Compare>::_Ret _STLportLess;
|
williamr@2
|
119 |
enum { is_default_less = __type2bool<_STLportLess>::_Ret };
|
williamr@2
|
120 |
|
williamr@2
|
121 |
typedef typename __select<is_default_less, _SType, _Tp>::_Ret _KeyStorageType;
|
williamr@2
|
122 |
enum { ptr_type = _StorageTypeInfo::use_const_volatile_void_ptr };
|
williamr@2
|
123 |
typedef typename __select<is_default_less && ptr_type,
|
williamr@2
|
124 |
_BinaryPredWrapper<_KeyStorageType, _Tp, _Compare>,
|
williamr@2
|
125 |
_Compare>::_Ret _CompareStorageType;
|
williamr@2
|
126 |
};
|
williamr@2
|
127 |
|
williamr@2
|
128 |
|
williamr@2
|
129 |
#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
|
williamr@2
|
130 |
/*
|
williamr@2
|
131 |
* Base struct to deal with qualifiers
|
williamr@2
|
132 |
*/
|
williamr@2
|
133 |
template <class _StorageT, class _QualifiedStorageT>
|
williamr@2
|
134 |
struct _VoidCastTraitsAux {
|
williamr@2
|
135 |
typedef _QualifiedStorageT void_cv_type;
|
williamr@2
|
136 |
typedef _StorageT void_type;
|
williamr@2
|
137 |
|
williamr@2
|
138 |
static void_type * uncv_ptr(void_cv_type *__ptr)
|
williamr@2
|
139 |
{ return __ptr; }
|
williamr@2
|
140 |
static void_type const* uncv_cptr(void_cv_type const*__ptr)
|
williamr@2
|
141 |
{ return __ptr; }
|
williamr@2
|
142 |
static void_type ** uncv_pptr(void_cv_type **__ptr)
|
williamr@2
|
143 |
{ return __ptr; }
|
williamr@2
|
144 |
static void_type & uncv_ref(void_cv_type & __ref)
|
williamr@2
|
145 |
{ return __ref; }
|
williamr@2
|
146 |
static void_type const& uncv_cref(void_cv_type const& __ref)
|
williamr@2
|
147 |
{ return __ref; }
|
williamr@2
|
148 |
static void_cv_type* cv_ptr(void_type *__ptr)
|
williamr@2
|
149 |
{ return __ptr; }
|
williamr@2
|
150 |
static void_cv_type const* cv_cptr(void_type const*__ptr)
|
williamr@2
|
151 |
{ return __ptr; }
|
williamr@2
|
152 |
static void_cv_type ** cv_pptr(void_type **__ptr)
|
williamr@2
|
153 |
{ return __ptr; }
|
williamr@2
|
154 |
static void_cv_type & cv_ref(void_type & __ref)
|
williamr@2
|
155 |
{ return __ref; }
|
williamr@2
|
156 |
static void_cv_type const& cv_cref(void_type const& __ref)
|
williamr@2
|
157 |
{ return __ref; }
|
williamr@2
|
158 |
};
|
williamr@2
|
159 |
|
williamr@2
|
160 |
template <class _VoidCVType>
|
williamr@2
|
161 |
struct _VoidCastTraitsAuxBase {
|
williamr@2
|
162 |
typedef _VoidCVType* void_cv_type;
|
williamr@2
|
163 |
typedef void* void_type;
|
williamr@2
|
164 |
|
williamr@2
|
165 |
static void_type* uncv_ptr(void_cv_type *__ptr)
|
williamr@2
|
166 |
{ return __CONST_CAST(void_type*, __ptr); }
|
williamr@2
|
167 |
static void_type const* uncv_cptr(void_cv_type const*__ptr)
|
williamr@2
|
168 |
{ return __CONST_CAST(void_type const*, __ptr); }
|
williamr@2
|
169 |
static void_type** uncv_pptr(void_cv_type **__ptr)
|
williamr@2
|
170 |
{ return __CONST_CAST(void_type**, __ptr); }
|
williamr@2
|
171 |
static void_type& uncv_ref(void_cv_type &__ref)
|
williamr@2
|
172 |
{ return __CONST_CAST(void_type&, __ref); }
|
williamr@2
|
173 |
static void_type const& uncv_cref(void_cv_type const& __ptr)
|
williamr@2
|
174 |
{ return __CONST_CAST(void_type const&, __ptr); }
|
williamr@2
|
175 |
// The reverse versions
|
williamr@2
|
176 |
static void_cv_type * cv_ptr(void_type *__ptr)
|
williamr@2
|
177 |
{ return __CONST_CAST(void_cv_type *, __ptr); }
|
williamr@2
|
178 |
static void_cv_type const* cv_cptr(void_type const*__ptr)
|
williamr@2
|
179 |
{ return __CONST_CAST(void_cv_type const*, __ptr); }
|
williamr@2
|
180 |
static void_cv_type ** cv_pptr(void_type **__ptr)
|
williamr@2
|
181 |
{ return __CONST_CAST(void_cv_type**, __ptr); }
|
williamr@2
|
182 |
static void_cv_type & cv_ref(void_type &__ref)
|
williamr@2
|
183 |
{ return __CONST_CAST(void_cv_type &, __ref); }
|
williamr@2
|
184 |
static void_cv_type const& cv_cref(void_type const& __ref)
|
williamr@2
|
185 |
{ return __CONST_CAST(void_cv_type const&, __ref); }
|
williamr@2
|
186 |
};
|
williamr@2
|
187 |
|
williamr@2
|
188 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
189 |
struct _VoidCastTraitsAux<void*, const void*> : _VoidCastTraitsAuxBase<void const>
|
williamr@2
|
190 |
{};
|
williamr@2
|
191 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
192 |
struct _VoidCastTraitsAux<void*, volatile void*> : _VoidCastTraitsAuxBase<void volatile>
|
williamr@2
|
193 |
{};
|
williamr@2
|
194 |
_STLP_TEMPLATE_NULL
|
williamr@2
|
195 |
struct _VoidCastTraitsAux<void*, const volatile void*> : _VoidCastTraitsAuxBase<void const volatile>
|
williamr@2
|
196 |
{};
|
williamr@2
|
197 |
|
williamr@2
|
198 |
template <class _StorageT, class _ValueT>
|
williamr@2
|
199 |
struct _CastTraits {
|
williamr@2
|
200 |
typedef _ValueT value_type;
|
williamr@2
|
201 |
typedef typename _StorageType<_ValueT>::_QualifiedType _QualifiedStorageT;
|
williamr@2
|
202 |
typedef _VoidCastTraitsAux<_StorageT, _QualifiedStorageT> cv_traits;
|
williamr@2
|
203 |
typedef typename cv_traits::void_type void_type;
|
williamr@2
|
204 |
typedef typename cv_traits::void_cv_type void_cv_type;
|
williamr@2
|
205 |
|
williamr@2
|
206 |
static value_type * to_value_type_ptr(void_type *__ptr)
|
williamr@2
|
207 |
{ return __REINTERPRET_CAST(value_type *, cv_traits::cv_ptr(__ptr)); }
|
williamr@2
|
208 |
static value_type const* to_value_type_cptr(void_type const*__ptr)
|
williamr@2
|
209 |
{ return __REINTERPRET_CAST(value_type const*, cv_traits::cv_cptr(__ptr)); }
|
williamr@2
|
210 |
static value_type ** to_value_type_pptr(void_type **__ptr)
|
williamr@2
|
211 |
{ return __REINTERPRET_CAST(value_type **, cv_traits::cv_pptr(__ptr)); }
|
williamr@2
|
212 |
static value_type & to_value_type_ref(void_type &__ref)
|
williamr@2
|
213 |
{ return __REINTERPRET_CAST(value_type &, cv_traits::cv_ref(__ref)); }
|
williamr@2
|
214 |
static value_type const& to_value_type_cref(void_type const& __ptr)
|
williamr@2
|
215 |
{ return __REINTERPRET_CAST(value_type const&, cv_traits::cv_cref(__ptr)); }
|
williamr@2
|
216 |
// Reverse versions
|
williamr@2
|
217 |
static void_type * to_storage_type_ptr(value_type *__ptr)
|
williamr@2
|
218 |
{ return cv_traits::uncv_ptr(__REINTERPRET_CAST(void_cv_type *, __ptr)); }
|
williamr@2
|
219 |
static void_type const* to_storage_type_cptr(value_type const*__ptr)
|
williamr@2
|
220 |
{ return cv_traits::uncv_cptr(__REINTERPRET_CAST(void_cv_type const*, __ptr)); }
|
williamr@2
|
221 |
static void_type ** to_storage_type_pptr(value_type **__ptr)
|
williamr@2
|
222 |
{ return cv_traits::uncv_pptr(__REINTERPRET_CAST(void_cv_type **, __ptr)); }
|
williamr@2
|
223 |
static void_type const& to_storage_type_cref(value_type const& __ref)
|
williamr@2
|
224 |
{ return cv_traits::uncv_cref(__REINTERPRET_CAST(void_cv_type const&, __ref)); }
|
williamr@2
|
225 |
|
williamr@2
|
226 |
//Method used to treat set container template method extension
|
williamr@2
|
227 |
static void_type const& to_storage_type_crefT(value_type const& __ref)
|
williamr@2
|
228 |
{ return to_storage_type_cref(__ref); }
|
williamr@2
|
229 |
};
|
williamr@2
|
230 |
|
williamr@2
|
231 |
template <class _Tp>
|
williamr@2
|
232 |
struct _CastTraits<_Tp, _Tp> {
|
williamr@2
|
233 |
typedef _Tp storage_type;
|
williamr@2
|
234 |
typedef _Tp value_type;
|
williamr@2
|
235 |
|
williamr@2
|
236 |
static value_type * to_value_type_ptr(storage_type *__ptr)
|
williamr@2
|
237 |
{ return __ptr; }
|
williamr@2
|
238 |
static value_type const* to_value_type_cptr(storage_type const*__ptr)
|
williamr@2
|
239 |
{ return __ptr; }
|
williamr@2
|
240 |
static value_type ** to_value_type_pptr(storage_type **__ptr)
|
williamr@2
|
241 |
{ return __ptr; }
|
williamr@2
|
242 |
static value_type & to_value_type_ref(storage_type &__ref)
|
williamr@2
|
243 |
{ return __ref; }
|
williamr@2
|
244 |
static value_type const& to_value_type_cref(storage_type const&__ref)
|
williamr@2
|
245 |
{ return __ref; }
|
williamr@2
|
246 |
// Reverse versions
|
williamr@2
|
247 |
static storage_type * to_storage_type_ptr(value_type *__ptr)
|
williamr@2
|
248 |
{ return __ptr; }
|
williamr@2
|
249 |
static storage_type const* to_storage_type_cptr(value_type const*__ptr)
|
williamr@2
|
250 |
{ return __ptr; }
|
williamr@2
|
251 |
static storage_type ** to_storage_type_pptr(value_type **__ptr)
|
williamr@2
|
252 |
{ return __ptr; }
|
williamr@2
|
253 |
static storage_type const& to_storage_type_cref(value_type const& __ref)
|
williamr@2
|
254 |
{ return __ref; }
|
williamr@2
|
255 |
|
williamr@2
|
256 |
//Method used to treat set container template method extension
|
williamr@2
|
257 |
template <class _Tp1>
|
williamr@2
|
258 |
static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
|
williamr@2
|
259 |
{ return __ref; }
|
williamr@2
|
260 |
};
|
williamr@2
|
261 |
|
williamr@2
|
262 |
#define _STLP_USE_ITERATOR_WRAPPER
|
williamr@2
|
263 |
|
williamr@2
|
264 |
template <class _StorageT, class _ValueT, class _Iterator>
|
williamr@2
|
265 |
struct _IteWrapper {
|
williamr@2
|
266 |
typedef _CastTraits<_StorageT, _ValueT> cast_traits;
|
williamr@2
|
267 |
typedef iterator_traits<_Iterator> _IteTraits;
|
williamr@2
|
268 |
|
williamr@2
|
269 |
typedef typename _IteTraits::iterator_category iterator_category;
|
williamr@2
|
270 |
typedef _StorageT value_type;
|
williamr@2
|
271 |
typedef typename _IteTraits::difference_type difference_type;
|
williamr@2
|
272 |
typedef value_type* pointer;
|
williamr@2
|
273 |
typedef value_type const& const_reference;
|
williamr@2
|
274 |
//This wrapper won't be used for input so to avoid surprise
|
williamr@2
|
275 |
//the reference type will be a const reference:
|
williamr@2
|
276 |
typedef const_reference reference;
|
williamr@2
|
277 |
|
williamr@2
|
278 |
typedef _IteWrapper<_StorageT, _ValueT, _Iterator> _Self;
|
williamr@2
|
279 |
typedef _Self _Ite;
|
williamr@2
|
280 |
|
williamr@2
|
281 |
_IteWrapper(_Iterator &__ite) : _M_ite(__ite) {}
|
williamr@2
|
282 |
|
williamr@2
|
283 |
const_reference operator*() const { return cast_traits::to_storage_type_cref(*_M_ite); }
|
williamr@2
|
284 |
|
williamr@2
|
285 |
_Self& operator= (_Self const& __rhs) {
|
williamr@2
|
286 |
_M_ite = __rhs._M_ite;
|
williamr@2
|
287 |
return *this;
|
williamr@2
|
288 |
}
|
williamr@2
|
289 |
|
williamr@2
|
290 |
_Self& operator++() {
|
williamr@2
|
291 |
++_M_ite;
|
williamr@2
|
292 |
return *this;
|
williamr@2
|
293 |
}
|
williamr@2
|
294 |
|
williamr@2
|
295 |
_Self& operator--() {
|
williamr@2
|
296 |
--_M_ite;
|
williamr@2
|
297 |
return *this;
|
williamr@2
|
298 |
}
|
williamr@2
|
299 |
|
williamr@2
|
300 |
_Self& operator += (difference_type __offset) {
|
williamr@2
|
301 |
_M_ite += __offset;
|
williamr@2
|
302 |
return *this;
|
williamr@2
|
303 |
}
|
williamr@2
|
304 |
difference_type operator -(_Self const& __other) const
|
williamr@2
|
305 |
{ return _M_ite - __other._M_ite; }
|
williamr@2
|
306 |
|
williamr@2
|
307 |
bool operator == (_Self const& __other) const
|
williamr@2
|
308 |
{ return _M_ite == __other._M_ite; }
|
williamr@2
|
309 |
|
williamr@2
|
310 |
bool operator != (_Self const& __other) const
|
williamr@2
|
311 |
{ return _M_ite != __other._M_ite; }
|
williamr@2
|
312 |
|
williamr@2
|
313 |
bool operator < (_Self const& __rhs) const
|
williamr@2
|
314 |
{ return _M_ite < __rhs._M_ite; }
|
williamr@2
|
315 |
|
williamr@2
|
316 |
private:
|
williamr@2
|
317 |
_Iterator _M_ite;
|
williamr@2
|
318 |
};
|
williamr@2
|
319 |
|
williamr@2
|
320 |
template <class _Tp, class _Iterator>
|
williamr@2
|
321 |
struct _IteWrapper<_Tp, _Tp, _Iterator>
|
williamr@2
|
322 |
{ typedef _Iterator _Ite; };
|
williamr@2
|
323 |
|
williamr@2
|
324 |
#else
|
williamr@2
|
325 |
|
williamr@2
|
326 |
/*
|
williamr@2
|
327 |
* In this config the storage type is qualified in respect of the
|
williamr@2
|
328 |
* value_type qualification. Simple reinterpret_cast is enough.
|
williamr@2
|
329 |
*/
|
williamr@2
|
330 |
template <class _StorageT, class _ValueT>
|
williamr@2
|
331 |
struct _CastTraits {
|
williamr@2
|
332 |
typedef _StorageT storage_type;
|
williamr@2
|
333 |
typedef _ValueT value_type;
|
williamr@2
|
334 |
|
williamr@2
|
335 |
static value_type * to_value_type_ptr(storage_type *__ptr)
|
williamr@2
|
336 |
{ return __REINTERPRET_CAST(value_type*, __ptr); }
|
williamr@2
|
337 |
static value_type const* to_value_type_cptr(storage_type const*__ptr)
|
williamr@2
|
338 |
{ return __REINTERPRET_CAST(value_type const*, __ptr); }
|
williamr@2
|
339 |
static value_type ** to_value_type_pptr(storage_type **__ptr)
|
williamr@2
|
340 |
{ return __REINTERPRET_CAST(value_type **, __ptr); }
|
williamr@2
|
341 |
static value_type & to_value_type_ref(storage_type &__ref)
|
williamr@2
|
342 |
{ return __REINTERPRET_CAST(value_type&, __ref); }
|
williamr@2
|
343 |
static value_type const& to_value_type_cref(storage_type const&__ref)
|
williamr@2
|
344 |
{ return __REINTERPRET_CAST(value_type const&, __ref); }
|
williamr@2
|
345 |
// Reverse versions
|
williamr@2
|
346 |
static storage_type * to_storage_type_ptr(value_type *__ptr)
|
williamr@2
|
347 |
{ return __REINTERPRET_CAST(storage_type*, __ptr); }
|
williamr@2
|
348 |
static storage_type const* to_storage_type_cptr(value_type const*__ptr)
|
williamr@2
|
349 |
{ return __REINTERPRET_CAST(storage_type const*, __ptr); }
|
williamr@2
|
350 |
static storage_type ** to_storage_type_pptr(value_type **__ptr)
|
williamr@2
|
351 |
{ return __REINTERPRET_CAST(storage_type **, __ptr); }
|
williamr@2
|
352 |
static storage_type const& to_storage_type_cref(value_type const&__ref)
|
williamr@2
|
353 |
{ return __REINTERPRET_CAST(storage_type const&, __ref); }
|
williamr@2
|
354 |
template <class _Tp1>
|
williamr@2
|
355 |
static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
|
williamr@2
|
356 |
{ return __ref; }
|
williamr@2
|
357 |
};
|
williamr@2
|
358 |
|
williamr@2
|
359 |
#endif
|
williamr@2
|
360 |
|
williamr@2
|
361 |
//Wrapper functors:
|
williamr@2
|
362 |
template <class _StorageT, class _ValueT, class _UnaryPredicate>
|
williamr@2
|
363 |
struct _UnaryPredWrapper {
|
williamr@2
|
364 |
typedef _CastTraits<_StorageT, _ValueT> cast_traits;
|
williamr@2
|
365 |
|
williamr@2
|
366 |
_UnaryPredWrapper (_UnaryPredicate const& __pred) : _M_pred(__pred) {}
|
williamr@2
|
367 |
|
williamr@2
|
368 |
bool operator () (_StorageT const& __ref) const
|
williamr@2
|
369 |
{ return _M_pred(cast_traits::to_value_type_cref(__ref)); }
|
williamr@2
|
370 |
|
williamr@2
|
371 |
private:
|
williamr@2
|
372 |
_UnaryPredicate _M_pred;
|
williamr@2
|
373 |
};
|
williamr@2
|
374 |
|
williamr@2
|
375 |
template <class _StorageT, class _ValueT, class _BinaryPredicate>
|
williamr@2
|
376 |
struct _BinaryPredWrapper {
|
williamr@2
|
377 |
typedef _CastTraits<_StorageT, _ValueT> cast_traits;
|
williamr@2
|
378 |
|
williamr@2
|
379 |
_BinaryPredWrapper () {}
|
williamr@2
|
380 |
_BinaryPredWrapper (_BinaryPredicate const& __pred) : _M_pred(__pred) {}
|
williamr@2
|
381 |
|
williamr@2
|
382 |
_BinaryPredicate get_pred() const { return _M_pred; }
|
williamr@2
|
383 |
|
williamr@2
|
384 |
bool operator () (_StorageT const& __fst, _StorageT const& __snd) const
|
williamr@2
|
385 |
{ return _M_pred(cast_traits::to_value_type_cref(__fst), cast_traits::to_value_type_cref(__snd)); }
|
williamr@2
|
386 |
|
williamr@2
|
387 |
//Cast operator used to transparently access underlying predicate
|
williamr@2
|
388 |
//in set::key_comp() method
|
williamr@2
|
389 |
operator _BinaryPredicate() const
|
williamr@2
|
390 |
{ return _M_pred; }
|
williamr@2
|
391 |
|
williamr@2
|
392 |
private:
|
williamr@2
|
393 |
_BinaryPredicate _M_pred;
|
williamr@2
|
394 |
};
|
williamr@2
|
395 |
|
williamr@2
|
396 |
_STLP_MOVE_TO_STD_NAMESPACE
|
williamr@2
|
397 |
|
williamr@2
|
398 |
_STLP_END_NAMESPACE
|
williamr@2
|
399 |
|
williamr@2
|
400 |
#endif /* _STLP_POINTERS_SPEC_TOOLS_H */
|