epoc32/include/tools/stlport/stl/pointers/_tools.h
branchSymbian3
changeset 4 837f303aceeb
parent 2 2fe1408b6811
     1.1 --- a/epoc32/include/tools/stlport/stl/pointers/_tools.h	Wed Mar 31 12:27:01 2010 +0100
     1.2 +++ b/epoc32/include/tools/stlport/stl/pointers/_tools.h	Wed Mar 31 12:33:34 2010 +0100
     1.3 @@ -1,400 +1,400 @@
     1.4 -/*
     1.5 - * Copyright (c) 2003
     1.6 - * Francois Dumont
     1.7 - *
     1.8 - * This material is provided "as is", with absolutely no warranty expressed
     1.9 - * or implied. Any use is at your own risk.
    1.10 - *
    1.11 - * Permission to use or copy this software for any purpose is hereby granted
    1.12 - * without fee, provided the above notices are retained on all copies.
    1.13 - * Permission to modify the code and to distribute modified code is granted,
    1.14 - * provided the above notices are retained, and a notice that the code was
    1.15 - * modified is included with the above copyright notice.
    1.16 - *
    1.17 - */
    1.18 -
    1.19 -/* NOTE: This is an internal header file, included by other STL headers.
    1.20 - *   You should not attempt to use it directly.
    1.21 - */
    1.22 -
    1.23 -#ifndef _STLP_POINTERS_SPEC_TOOLS_H
    1.24 -#define _STLP_POINTERS_SPEC_TOOLS_H
    1.25 -
    1.26 -#ifndef _STLP_TYPE_TRAITS_H
    1.27 -#  include <stl/type_traits.h>
    1.28 -#endif
    1.29 -
    1.30 -_STLP_BEGIN_NAMESPACE
    1.31 -
    1.32 -//Some usefull declarations:
    1.33 -template <class _Tp> struct less;
    1.34 -
    1.35 -_STLP_MOVE_TO_PRIV_NAMESPACE
    1.36 -
    1.37 -template <class _StorageT, class _ValueT, class _BinaryPredicate>
    1.38 -struct _BinaryPredWrapper;
    1.39 -
    1.40 -/*
    1.41 - * Since the compiler only allows at most one non-trivial
    1.42 - * implicit conversion we can make use of a shim class to
    1.43 - * be sure that functions below doesn't accept classes with
    1.44 - * implicit pointer conversion operators
    1.45 - */
    1.46 -struct _ConstVolatileVoidPointerShim
    1.47 -{ _ConstVolatileVoidPointerShim(const volatile void*); };
    1.48 -
    1.49 -//The dispatch functions:
    1.50 -struct _VoidPointerShim
    1.51 -{ _VoidPointerShim(void*); };
    1.52 -struct _ConstVoidPointerShim
    1.53 -{ _ConstVoidPointerShim(const void*); };
    1.54 -struct _VolatileVoidPointerShim
    1.55 -{ _VolatileVoidPointerShim(volatile void*); };
    1.56 -
    1.57 -template <class _Tp>
    1.58 -char _UseVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
    1.59 -char _UseVoidPtrStorageType(const __true_type& /*POD*/, ...);
    1.60 -char* _UseVoidPtrStorageType(const __true_type& /*POD*/, _VoidPointerShim);
    1.61 -
    1.62 -template <class _Tp>
    1.63 -char _UseConstVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
    1.64 -char _UseConstVoidPtrStorageType(const __true_type& /*POD*/, ...);
    1.65 -char* _UseConstVoidPtrStorageType(const __true_type& /*POD*/, _ConstVoidPointerShim);
    1.66 -
    1.67 -template <class _Tp>
    1.68 -char _UseVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
    1.69 -char _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
    1.70 -char* _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, _VolatileVoidPointerShim);
    1.71 -
    1.72 -template <class _Tp>
    1.73 -char _UseConstVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
    1.74 -char _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
    1.75 -char* _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, _ConstVolatileVoidPointerShim);
    1.76 -
    1.77 -template <class _Tp>
    1.78 -struct _StorageType {
    1.79 -  typedef typename __type_traits<_Tp>::is_POD_type _PODType;
    1.80 -  static _Tp __null_rep();
    1.81 -
    1.82 -  enum { use_void_ptr = (sizeof(_UseVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
    1.83 -  enum { use_const_void_ptr = (sizeof(_UseConstVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
    1.84 -  enum { use_volatile_void_ptr = (sizeof(_UseVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
    1.85 -  enum { use_const_volatile_void_ptr = (sizeof(_UseConstVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
    1.86 -
    1.87 -  typedef typename __select<!use_const_volatile_void_ptr,
    1.88 -                            _Tp,
    1.89 -          typename __select<use_void_ptr,
    1.90 -                            void*,
    1.91 -          typename __select<use_const_void_ptr,
    1.92 -                            const void*,
    1.93 -          typename __select<use_volatile_void_ptr,
    1.94 -                            volatile void*,
    1.95 -                            const volatile void*>::_Ret >::_Ret >::_Ret >::_Ret _QualifiedType;
    1.96 -
    1.97 -#if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
    1.98 -  /* If the compiler do not support the iterator_traits structure we cannot wrap
    1.99 -   * iterators pass to container template methods. The iterator dereferenced value
   1.100 -   * has to be storable without any cast in the chosen storage type. To guaranty
   1.101 -   * that the void pointer has to be correctly qualified.
   1.102 -   */
   1.103 -  typedef _QualifiedType _Type;
   1.104 -#else
   1.105 -  /* With iterator_traits we can wrap passed iterators and make the necessary casts.
   1.106 -   * We can always use a simple void* storage type:
   1.107 -   */
   1.108 -  typedef typename __select<use_const_volatile_void_ptr,
   1.109 -                            void*,
   1.110 -                            _Tp>::_Ret _Type;
   1.111 -#endif
   1.112 -};
   1.113 -
   1.114 -template <class _Tp, class _Compare>
   1.115 -struct _AssocStorageTypes {
   1.116 -  typedef _StorageType<_Tp> _StorageTypeInfo;
   1.117 -  typedef typename _StorageTypeInfo::_Type _SType;
   1.118 -
   1.119 -  //We need to also check that the comparison functor used to instanciate the assoc container
   1.120 -  //is the default Standard less implementation:
   1.121 -  typedef typename _IsSTLportClass<_Compare>::_Ret _STLportLess;
   1.122 -  enum { is_default_less = __type2bool<_STLportLess>::_Ret };
   1.123 -
   1.124 -  typedef typename __select<is_default_less, _SType, _Tp>::_Ret _KeyStorageType;
   1.125 -  enum { ptr_type = _StorageTypeInfo::use_const_volatile_void_ptr };
   1.126 -  typedef typename __select<is_default_less && ptr_type,
   1.127 -                            _BinaryPredWrapper<_KeyStorageType, _Tp, _Compare>,
   1.128 -                            _Compare>::_Ret _CompareStorageType;
   1.129 -};
   1.130 -
   1.131 -
   1.132 -#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.133 -/*
   1.134 - * Base struct to deal with qualifiers
   1.135 - */
   1.136 -template <class _StorageT, class _QualifiedStorageT>
   1.137 -struct _VoidCastTraitsAux {
   1.138 -  typedef _QualifiedStorageT void_cv_type;
   1.139 -  typedef _StorageT void_type;
   1.140 -
   1.141 -  static void_type * uncv_ptr(void_cv_type *__ptr)
   1.142 -  { return __ptr; }
   1.143 -  static void_type const* uncv_cptr(void_cv_type const*__ptr)
   1.144 -  { return __ptr; }
   1.145 -  static void_type ** uncv_pptr(void_cv_type **__ptr)
   1.146 -  { return __ptr; }
   1.147 -  static void_type & uncv_ref(void_cv_type & __ref)
   1.148 -  { return __ref; }
   1.149 -  static void_type const& uncv_cref(void_cv_type const& __ref)
   1.150 -  { return __ref; }
   1.151 -  static void_cv_type* cv_ptr(void_type *__ptr)
   1.152 -  { return __ptr; }
   1.153 -  static void_cv_type const* cv_cptr(void_type const*__ptr)
   1.154 -  { return __ptr; }
   1.155 -  static void_cv_type ** cv_pptr(void_type **__ptr)
   1.156 -  { return __ptr; }
   1.157 -  static void_cv_type & cv_ref(void_type & __ref)
   1.158 -  { return __ref; }
   1.159 -  static void_cv_type const& cv_cref(void_type const& __ref)
   1.160 -  { return __ref; }
   1.161 -};
   1.162 -
   1.163 -template <class _VoidCVType>
   1.164 -struct _VoidCastTraitsAuxBase {
   1.165 -  typedef _VoidCVType* void_cv_type;
   1.166 -  typedef void* void_type;
   1.167 -
   1.168 -  static void_type* uncv_ptr(void_cv_type *__ptr)
   1.169 -  { return __CONST_CAST(void_type*, __ptr); }
   1.170 -  static void_type const* uncv_cptr(void_cv_type const*__ptr)
   1.171 -  { return __CONST_CAST(void_type const*, __ptr); }
   1.172 -  static void_type** uncv_pptr(void_cv_type **__ptr)
   1.173 -  { return __CONST_CAST(void_type**, __ptr); }
   1.174 -  static void_type& uncv_ref(void_cv_type &__ref)
   1.175 -  { return __CONST_CAST(void_type&, __ref); }
   1.176 -  static void_type const& uncv_cref(void_cv_type const& __ptr)
   1.177 -  { return __CONST_CAST(void_type const&, __ptr); }
   1.178 -  // The reverse versions
   1.179 -  static void_cv_type * cv_ptr(void_type *__ptr)
   1.180 -  { return __CONST_CAST(void_cv_type *, __ptr); }
   1.181 -  static void_cv_type const* cv_cptr(void_type const*__ptr)
   1.182 -  { return __CONST_CAST(void_cv_type const*, __ptr); }
   1.183 -  static void_cv_type ** cv_pptr(void_type **__ptr)
   1.184 -  { return __CONST_CAST(void_cv_type**, __ptr); }
   1.185 -  static void_cv_type & cv_ref(void_type &__ref)
   1.186 -  { return __CONST_CAST(void_cv_type &, __ref); }
   1.187 -  static void_cv_type const& cv_cref(void_type const& __ref)
   1.188 -  { return __CONST_CAST(void_cv_type const&, __ref); }
   1.189 -};
   1.190 -
   1.191 -_STLP_TEMPLATE_NULL
   1.192 -struct _VoidCastTraitsAux<void*, const void*> : _VoidCastTraitsAuxBase<void const>
   1.193 -{};
   1.194 -_STLP_TEMPLATE_NULL
   1.195 -struct _VoidCastTraitsAux<void*, volatile void*> : _VoidCastTraitsAuxBase<void volatile>
   1.196 -{};
   1.197 -_STLP_TEMPLATE_NULL
   1.198 -struct _VoidCastTraitsAux<void*, const volatile void*> : _VoidCastTraitsAuxBase<void const volatile>
   1.199 -{};
   1.200 -
   1.201 -template <class _StorageT, class _ValueT>
   1.202 -struct _CastTraits {
   1.203 -  typedef _ValueT value_type;
   1.204 -  typedef typename _StorageType<_ValueT>::_QualifiedType _QualifiedStorageT;
   1.205 -  typedef _VoidCastTraitsAux<_StorageT, _QualifiedStorageT> cv_traits;
   1.206 -  typedef typename cv_traits::void_type void_type;
   1.207 -  typedef typename cv_traits::void_cv_type void_cv_type;
   1.208 -
   1.209 -  static value_type * to_value_type_ptr(void_type *__ptr)
   1.210 -  { return __REINTERPRET_CAST(value_type *, cv_traits::cv_ptr(__ptr)); }
   1.211 -  static value_type const* to_value_type_cptr(void_type const*__ptr)
   1.212 -  { return __REINTERPRET_CAST(value_type const*, cv_traits::cv_cptr(__ptr)); }
   1.213 -  static value_type ** to_value_type_pptr(void_type **__ptr)
   1.214 -  { return __REINTERPRET_CAST(value_type **, cv_traits::cv_pptr(__ptr)); }
   1.215 -  static value_type & to_value_type_ref(void_type &__ref)
   1.216 -  { return __REINTERPRET_CAST(value_type &, cv_traits::cv_ref(__ref)); }
   1.217 -  static value_type const& to_value_type_cref(void_type const& __ptr)
   1.218 -  { return __REINTERPRET_CAST(value_type const&, cv_traits::cv_cref(__ptr)); }
   1.219 -  // Reverse versions
   1.220 -  static void_type * to_storage_type_ptr(value_type *__ptr)
   1.221 -  { return cv_traits::uncv_ptr(__REINTERPRET_CAST(void_cv_type *, __ptr)); }
   1.222 -  static void_type const* to_storage_type_cptr(value_type const*__ptr)
   1.223 -  { return cv_traits::uncv_cptr(__REINTERPRET_CAST(void_cv_type const*, __ptr)); }
   1.224 -  static void_type ** to_storage_type_pptr(value_type **__ptr)
   1.225 -  { return cv_traits::uncv_pptr(__REINTERPRET_CAST(void_cv_type **, __ptr)); }
   1.226 -  static void_type const& to_storage_type_cref(value_type const& __ref)
   1.227 -  { return cv_traits::uncv_cref(__REINTERPRET_CAST(void_cv_type const&, __ref)); }
   1.228 -
   1.229 -  //Method used to treat set container template method extension
   1.230 -  static void_type const& to_storage_type_crefT(value_type const& __ref)
   1.231 -  { return to_storage_type_cref(__ref); }
   1.232 -};
   1.233 -
   1.234 -template <class _Tp>
   1.235 -struct _CastTraits<_Tp, _Tp> {
   1.236 -  typedef _Tp storage_type;
   1.237 -  typedef _Tp value_type;
   1.238 -
   1.239 -  static value_type * to_value_type_ptr(storage_type *__ptr)
   1.240 -  { return __ptr; }
   1.241 -  static value_type const* to_value_type_cptr(storage_type const*__ptr)
   1.242 -  { return __ptr; }
   1.243 -  static value_type ** to_value_type_pptr(storage_type **__ptr)
   1.244 -  { return __ptr; }
   1.245 -  static value_type & to_value_type_ref(storage_type &__ref)
   1.246 -  { return __ref; }
   1.247 -  static value_type const& to_value_type_cref(storage_type const&__ref)
   1.248 -  { return __ref; }
   1.249 -  // Reverse versions
   1.250 -  static storage_type * to_storage_type_ptr(value_type *__ptr)
   1.251 -  { return __ptr; }
   1.252 -  static storage_type const* to_storage_type_cptr(value_type const*__ptr)
   1.253 -  { return __ptr; }
   1.254 -  static storage_type ** to_storage_type_pptr(value_type **__ptr)
   1.255 -  { return __ptr; }
   1.256 -  static storage_type const& to_storage_type_cref(value_type const& __ref)
   1.257 -  { return __ref; }
   1.258 -
   1.259 -  //Method used to treat set container template method extension
   1.260 -  template <class _Tp1>
   1.261 -  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
   1.262 -  { return __ref; }
   1.263 -};
   1.264 -
   1.265 -#define _STLP_USE_ITERATOR_WRAPPER
   1.266 -
   1.267 -template <class _StorageT, class _ValueT, class _Iterator>
   1.268 -struct _IteWrapper {
   1.269 -  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.270 -  typedef iterator_traits<_Iterator> _IteTraits;
   1.271 -
   1.272 -  typedef typename _IteTraits::iterator_category iterator_category;
   1.273 -  typedef _StorageT value_type;
   1.274 -  typedef typename _IteTraits::difference_type difference_type;
   1.275 -  typedef value_type* pointer;
   1.276 -  typedef value_type const& const_reference;
   1.277 -  //This wrapper won't be used for input so to avoid surprise
   1.278 -  //the reference type will be a const reference:
   1.279 -  typedef const_reference reference;
   1.280 -
   1.281 -  typedef _IteWrapper<_StorageT, _ValueT, _Iterator> _Self;
   1.282 -  typedef _Self _Ite;
   1.283 -
   1.284 -  _IteWrapper(_Iterator &__ite) : _M_ite(__ite) {}
   1.285 -
   1.286 -  const_reference operator*() const { return cast_traits::to_storage_type_cref(*_M_ite); }
   1.287 -
   1.288 -  _Self& operator= (_Self const& __rhs) {
   1.289 -    _M_ite = __rhs._M_ite;
   1.290 -    return *this;
   1.291 -  }
   1.292 -
   1.293 -  _Self& operator++() {
   1.294 -    ++_M_ite;
   1.295 -    return *this;
   1.296 -  }
   1.297 -
   1.298 -  _Self& operator--() {
   1.299 -    --_M_ite;
   1.300 -    return *this;
   1.301 -  }
   1.302 -
   1.303 -  _Self& operator += (difference_type __offset) {
   1.304 -    _M_ite += __offset;
   1.305 -    return *this;
   1.306 -  }
   1.307 -  difference_type operator -(_Self const& __other) const
   1.308 -  { return _M_ite - __other._M_ite; }
   1.309 -
   1.310 -  bool operator == (_Self const& __other) const
   1.311 -  { return _M_ite == __other._M_ite; }
   1.312 -
   1.313 -  bool operator != (_Self const& __other) const
   1.314 -  { return _M_ite != __other._M_ite; }
   1.315 -
   1.316 -  bool operator < (_Self const& __rhs) const
   1.317 -  { return _M_ite < __rhs._M_ite; }
   1.318 -
   1.319 -private:
   1.320 -  _Iterator _M_ite;
   1.321 -};
   1.322 -
   1.323 -template <class _Tp, class _Iterator>
   1.324 -struct _IteWrapper<_Tp, _Tp, _Iterator>
   1.325 -{ typedef _Iterator _Ite; };
   1.326 -
   1.327 -#else
   1.328 -
   1.329 -/*
   1.330 - * In this config the storage type is qualified in respect of the
   1.331 - * value_type qualification. Simple reinterpret_cast is enough.
   1.332 - */
   1.333 -template <class _StorageT, class _ValueT>
   1.334 -struct _CastTraits {
   1.335 -  typedef _StorageT storage_type;
   1.336 -  typedef _ValueT value_type;
   1.337 -
   1.338 -  static value_type * to_value_type_ptr(storage_type *__ptr)
   1.339 -  { return __REINTERPRET_CAST(value_type*, __ptr); }
   1.340 -  static value_type const* to_value_type_cptr(storage_type const*__ptr)
   1.341 -  { return __REINTERPRET_CAST(value_type const*, __ptr); }
   1.342 -  static value_type ** to_value_type_pptr(storage_type **__ptr)
   1.343 -  { return __REINTERPRET_CAST(value_type **, __ptr); }
   1.344 -  static value_type & to_value_type_ref(storage_type &__ref)
   1.345 -  { return __REINTERPRET_CAST(value_type&, __ref); }
   1.346 -  static value_type const& to_value_type_cref(storage_type const&__ref)
   1.347 -  { return __REINTERPRET_CAST(value_type const&, __ref); }
   1.348 -  // Reverse versions
   1.349 -  static storage_type * to_storage_type_ptr(value_type *__ptr)
   1.350 -  { return __REINTERPRET_CAST(storage_type*, __ptr); }
   1.351 -  static storage_type const* to_storage_type_cptr(value_type const*__ptr)
   1.352 -  { return __REINTERPRET_CAST(storage_type const*, __ptr); }
   1.353 -  static storage_type ** to_storage_type_pptr(value_type **__ptr)
   1.354 -  { return __REINTERPRET_CAST(storage_type **, __ptr); }
   1.355 -  static storage_type const& to_storage_type_cref(value_type const&__ref)
   1.356 -  { return __REINTERPRET_CAST(storage_type const&, __ref); }
   1.357 -  template <class _Tp1>
   1.358 -  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
   1.359 -  { return __ref; }
   1.360 -};
   1.361 -
   1.362 -#endif
   1.363 -
   1.364 -//Wrapper functors:
   1.365 -template <class _StorageT, class _ValueT, class _UnaryPredicate>
   1.366 -struct _UnaryPredWrapper {
   1.367 -  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.368 -
   1.369 -  _UnaryPredWrapper (_UnaryPredicate const& __pred) : _M_pred(__pred) {}
   1.370 -
   1.371 -  bool operator () (_StorageT const& __ref) const
   1.372 -  { return _M_pred(cast_traits::to_value_type_cref(__ref)); }
   1.373 -
   1.374 -private:
   1.375 -  _UnaryPredicate _M_pred;
   1.376 -};
   1.377 -
   1.378 -template <class _StorageT, class _ValueT, class _BinaryPredicate>
   1.379 -struct _BinaryPredWrapper {
   1.380 -  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.381 -
   1.382 -  _BinaryPredWrapper () {}
   1.383 -  _BinaryPredWrapper (_BinaryPredicate const& __pred) : _M_pred(__pred) {}
   1.384 -
   1.385 -  _BinaryPredicate get_pred() const { return _M_pred; }
   1.386 -
   1.387 -  bool operator () (_StorageT const& __fst, _StorageT const& __snd) const
   1.388 -  { return _M_pred(cast_traits::to_value_type_cref(__fst), cast_traits::to_value_type_cref(__snd)); }
   1.389 -
   1.390 -  //Cast operator used to transparently access underlying predicate
   1.391 -  //in set::key_comp() method
   1.392 -  operator _BinaryPredicate() const
   1.393 -  { return _M_pred; }
   1.394 -
   1.395 -private:
   1.396 -  _BinaryPredicate _M_pred;
   1.397 -};
   1.398 -
   1.399 -_STLP_MOVE_TO_STD_NAMESPACE
   1.400 -
   1.401 -_STLP_END_NAMESPACE
   1.402 -
   1.403 -#endif /* _STLP_POINTERS_SPEC_TOOLS_H */
   1.404 +/*
   1.405 + * Copyright (c) 2003
   1.406 + * Francois Dumont
   1.407 + *
   1.408 + * This material is provided "as is", with absolutely no warranty expressed
   1.409 + * or implied. Any use is at your own risk.
   1.410 + *
   1.411 + * Permission to use or copy this software for any purpose is hereby granted
   1.412 + * without fee, provided the above notices are retained on all copies.
   1.413 + * Permission to modify the code and to distribute modified code is granted,
   1.414 + * provided the above notices are retained, and a notice that the code was
   1.415 + * modified is included with the above copyright notice.
   1.416 + *
   1.417 + */
   1.418 +
   1.419 +/* NOTE: This is an internal header file, included by other STL headers.
   1.420 + *   You should not attempt to use it directly.
   1.421 + */
   1.422 +
   1.423 +#ifndef _STLP_POINTERS_SPEC_TOOLS_H
   1.424 +#define _STLP_POINTERS_SPEC_TOOLS_H
   1.425 +
   1.426 +#ifndef _STLP_TYPE_TRAITS_H
   1.427 +#  include <stl/type_traits.h>
   1.428 +#endif
   1.429 +
   1.430 +_STLP_BEGIN_NAMESPACE
   1.431 +
   1.432 +//Some usefull declarations:
   1.433 +template <class _Tp> struct less;
   1.434 +
   1.435 +_STLP_MOVE_TO_PRIV_NAMESPACE
   1.436 +
   1.437 +template <class _StorageT, class _ValueT, class _BinaryPredicate>
   1.438 +struct _BinaryPredWrapper;
   1.439 +
   1.440 +/*
   1.441 + * Since the compiler only allows at most one non-trivial
   1.442 + * implicit conversion we can make use of a shim class to
   1.443 + * be sure that functions below doesn't accept classes with
   1.444 + * implicit pointer conversion operators
   1.445 + */
   1.446 +struct _ConstVolatileVoidPointerShim
   1.447 +{ _ConstVolatileVoidPointerShim(const volatile void*); };
   1.448 +
   1.449 +//The dispatch functions:
   1.450 +struct _VoidPointerShim
   1.451 +{ _VoidPointerShim(void*); };
   1.452 +struct _ConstVoidPointerShim
   1.453 +{ _ConstVoidPointerShim(const void*); };
   1.454 +struct _VolatileVoidPointerShim
   1.455 +{ _VolatileVoidPointerShim(volatile void*); };
   1.456 +
   1.457 +template <class _Tp>
   1.458 +char _UseVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
   1.459 +char _UseVoidPtrStorageType(const __true_type& /*POD*/, ...);
   1.460 +char* _UseVoidPtrStorageType(const __true_type& /*POD*/, _VoidPointerShim);
   1.461 +
   1.462 +template <class _Tp>
   1.463 +char _UseConstVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
   1.464 +char _UseConstVoidPtrStorageType(const __true_type& /*POD*/, ...);
   1.465 +char* _UseConstVoidPtrStorageType(const __true_type& /*POD*/, _ConstVoidPointerShim);
   1.466 +
   1.467 +template <class _Tp>
   1.468 +char _UseVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
   1.469 +char _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
   1.470 +char* _UseVolatileVoidPtrStorageType(const __true_type& /*POD*/, _VolatileVoidPointerShim);
   1.471 +
   1.472 +template <class _Tp>
   1.473 +char _UseConstVolatileVoidPtrStorageType(const __false_type& /*POD*/, const _Tp&);
   1.474 +char _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, ...);
   1.475 +char* _UseConstVolatileVoidPtrStorageType(const __true_type& /*POD*/, _ConstVolatileVoidPointerShim);
   1.476 +
   1.477 +template <class _Tp>
   1.478 +struct _StorageType {
   1.479 +  typedef typename __type_traits<_Tp>::is_POD_type _PODType;
   1.480 +  static _Tp __null_rep();
   1.481 +
   1.482 +  enum { use_void_ptr = (sizeof(_UseVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
   1.483 +  enum { use_const_void_ptr = (sizeof(_UseConstVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
   1.484 +  enum { use_volatile_void_ptr = (sizeof(_UseVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
   1.485 +  enum { use_const_volatile_void_ptr = (sizeof(_UseConstVolatileVoidPtrStorageType(_PODType(), __null_rep())) == sizeof(char*)) };
   1.486 +
   1.487 +  typedef typename __select<!use_const_volatile_void_ptr,
   1.488 +                            _Tp,
   1.489 +          typename __select<use_void_ptr,
   1.490 +                            void*,
   1.491 +          typename __select<use_const_void_ptr,
   1.492 +                            const void*,
   1.493 +          typename __select<use_volatile_void_ptr,
   1.494 +                            volatile void*,
   1.495 +                            const volatile void*>::_Ret >::_Ret >::_Ret >::_Ret _QualifiedType;
   1.496 +
   1.497 +#if !defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.498 +  /* If the compiler do not support the iterator_traits structure we cannot wrap
   1.499 +   * iterators pass to container template methods. The iterator dereferenced value
   1.500 +   * has to be storable without any cast in the chosen storage type. To guaranty
   1.501 +   * that the void pointer has to be correctly qualified.
   1.502 +   */
   1.503 +  typedef _QualifiedType _Type;
   1.504 +#else
   1.505 +  /* With iterator_traits we can wrap passed iterators and make the necessary casts.
   1.506 +   * We can always use a simple void* storage type:
   1.507 +   */
   1.508 +  typedef typename __select<use_const_volatile_void_ptr,
   1.509 +                            void*,
   1.510 +                            _Tp>::_Ret _Type;
   1.511 +#endif
   1.512 +};
   1.513 +
   1.514 +template <class _Tp, class _Compare>
   1.515 +struct _AssocStorageTypes {
   1.516 +  typedef _StorageType<_Tp> _StorageTypeInfo;
   1.517 +  typedef typename _StorageTypeInfo::_Type _SType;
   1.518 +
   1.519 +  //We need to also check that the comparison functor used to instanciate the assoc container
   1.520 +  //is the default Standard less implementation:
   1.521 +  typedef typename _IsSTLportClass<_Compare>::_Ret _STLportLess;
   1.522 +  enum { is_default_less = __type2bool<_STLportLess>::_Ret };
   1.523 +
   1.524 +  typedef typename __select<is_default_less, _SType, _Tp>::_Ret _KeyStorageType;
   1.525 +  enum { ptr_type = _StorageTypeInfo::use_const_volatile_void_ptr };
   1.526 +  typedef typename __select<is_default_less && ptr_type,
   1.527 +                            _BinaryPredWrapper<_KeyStorageType, _Tp, _Compare>,
   1.528 +                            _Compare>::_Ret _CompareStorageType;
   1.529 +};
   1.530 +
   1.531 +
   1.532 +#if defined (_STLP_CLASS_PARTIAL_SPECIALIZATION)
   1.533 +/*
   1.534 + * Base struct to deal with qualifiers
   1.535 + */
   1.536 +template <class _StorageT, class _QualifiedStorageT>
   1.537 +struct _VoidCastTraitsAux {
   1.538 +  typedef _QualifiedStorageT void_cv_type;
   1.539 +  typedef _StorageT void_type;
   1.540 +
   1.541 +  static void_type * uncv_ptr(void_cv_type *__ptr)
   1.542 +  { return __ptr; }
   1.543 +  static void_type const* uncv_cptr(void_cv_type const*__ptr)
   1.544 +  { return __ptr; }
   1.545 +  static void_type ** uncv_pptr(void_cv_type **__ptr)
   1.546 +  { return __ptr; }
   1.547 +  static void_type & uncv_ref(void_cv_type & __ref)
   1.548 +  { return __ref; }
   1.549 +  static void_type const& uncv_cref(void_cv_type const& __ref)
   1.550 +  { return __ref; }
   1.551 +  static void_cv_type* cv_ptr(void_type *__ptr)
   1.552 +  { return __ptr; }
   1.553 +  static void_cv_type const* cv_cptr(void_type const*__ptr)
   1.554 +  { return __ptr; }
   1.555 +  static void_cv_type ** cv_pptr(void_type **__ptr)
   1.556 +  { return __ptr; }
   1.557 +  static void_cv_type & cv_ref(void_type & __ref)
   1.558 +  { return __ref; }
   1.559 +  static void_cv_type const& cv_cref(void_type const& __ref)
   1.560 +  { return __ref; }
   1.561 +};
   1.562 +
   1.563 +template <class _VoidCVType>
   1.564 +struct _VoidCastTraitsAuxBase {
   1.565 +  typedef _VoidCVType* void_cv_type;
   1.566 +  typedef void* void_type;
   1.567 +
   1.568 +  static void_type* uncv_ptr(void_cv_type *__ptr)
   1.569 +  { return __CONST_CAST(void_type*, __ptr); }
   1.570 +  static void_type const* uncv_cptr(void_cv_type const*__ptr)
   1.571 +  { return __CONST_CAST(void_type const*, __ptr); }
   1.572 +  static void_type** uncv_pptr(void_cv_type **__ptr)
   1.573 +  { return __CONST_CAST(void_type**, __ptr); }
   1.574 +  static void_type& uncv_ref(void_cv_type &__ref)
   1.575 +  { return __CONST_CAST(void_type&, __ref); }
   1.576 +  static void_type const& uncv_cref(void_cv_type const& __ptr)
   1.577 +  { return __CONST_CAST(void_type const&, __ptr); }
   1.578 +  // The reverse versions
   1.579 +  static void_cv_type * cv_ptr(void_type *__ptr)
   1.580 +  { return __CONST_CAST(void_cv_type *, __ptr); }
   1.581 +  static void_cv_type const* cv_cptr(void_type const*__ptr)
   1.582 +  { return __CONST_CAST(void_cv_type const*, __ptr); }
   1.583 +  static void_cv_type ** cv_pptr(void_type **__ptr)
   1.584 +  { return __CONST_CAST(void_cv_type**, __ptr); }
   1.585 +  static void_cv_type & cv_ref(void_type &__ref)
   1.586 +  { return __CONST_CAST(void_cv_type &, __ref); }
   1.587 +  static void_cv_type const& cv_cref(void_type const& __ref)
   1.588 +  { return __CONST_CAST(void_cv_type const&, __ref); }
   1.589 +};
   1.590 +
   1.591 +_STLP_TEMPLATE_NULL
   1.592 +struct _VoidCastTraitsAux<void*, const void*> : _VoidCastTraitsAuxBase<void const>
   1.593 +{};
   1.594 +_STLP_TEMPLATE_NULL
   1.595 +struct _VoidCastTraitsAux<void*, volatile void*> : _VoidCastTraitsAuxBase<void volatile>
   1.596 +{};
   1.597 +_STLP_TEMPLATE_NULL
   1.598 +struct _VoidCastTraitsAux<void*, const volatile void*> : _VoidCastTraitsAuxBase<void const volatile>
   1.599 +{};
   1.600 +
   1.601 +template <class _StorageT, class _ValueT>
   1.602 +struct _CastTraits {
   1.603 +  typedef _ValueT value_type;
   1.604 +  typedef typename _StorageType<_ValueT>::_QualifiedType _QualifiedStorageT;
   1.605 +  typedef _VoidCastTraitsAux<_StorageT, _QualifiedStorageT> cv_traits;
   1.606 +  typedef typename cv_traits::void_type void_type;
   1.607 +  typedef typename cv_traits::void_cv_type void_cv_type;
   1.608 +
   1.609 +  static value_type * to_value_type_ptr(void_type *__ptr)
   1.610 +  { return __REINTERPRET_CAST(value_type *, cv_traits::cv_ptr(__ptr)); }
   1.611 +  static value_type const* to_value_type_cptr(void_type const*__ptr)
   1.612 +  { return __REINTERPRET_CAST(value_type const*, cv_traits::cv_cptr(__ptr)); }
   1.613 +  static value_type ** to_value_type_pptr(void_type **__ptr)
   1.614 +  { return __REINTERPRET_CAST(value_type **, cv_traits::cv_pptr(__ptr)); }
   1.615 +  static value_type & to_value_type_ref(void_type &__ref)
   1.616 +  { return __REINTERPRET_CAST(value_type &, cv_traits::cv_ref(__ref)); }
   1.617 +  static value_type const& to_value_type_cref(void_type const& __ptr)
   1.618 +  { return __REINTERPRET_CAST(value_type const&, cv_traits::cv_cref(__ptr)); }
   1.619 +  // Reverse versions
   1.620 +  static void_type * to_storage_type_ptr(value_type *__ptr)
   1.621 +  { return cv_traits::uncv_ptr(__REINTERPRET_CAST(void_cv_type *, __ptr)); }
   1.622 +  static void_type const* to_storage_type_cptr(value_type const*__ptr)
   1.623 +  { return cv_traits::uncv_cptr(__REINTERPRET_CAST(void_cv_type const*, __ptr)); }
   1.624 +  static void_type ** to_storage_type_pptr(value_type **__ptr)
   1.625 +  { return cv_traits::uncv_pptr(__REINTERPRET_CAST(void_cv_type **, __ptr)); }
   1.626 +  static void_type const& to_storage_type_cref(value_type const& __ref)
   1.627 +  { return cv_traits::uncv_cref(__REINTERPRET_CAST(void_cv_type const&, __ref)); }
   1.628 +
   1.629 +  //Method used to treat set container template method extension
   1.630 +  static void_type const& to_storage_type_crefT(value_type const& __ref)
   1.631 +  { return to_storage_type_cref(__ref); }
   1.632 +};
   1.633 +
   1.634 +template <class _Tp>
   1.635 +struct _CastTraits<_Tp, _Tp> {
   1.636 +  typedef _Tp storage_type;
   1.637 +  typedef _Tp value_type;
   1.638 +
   1.639 +  static value_type * to_value_type_ptr(storage_type *__ptr)
   1.640 +  { return __ptr; }
   1.641 +  static value_type const* to_value_type_cptr(storage_type const*__ptr)
   1.642 +  { return __ptr; }
   1.643 +  static value_type ** to_value_type_pptr(storage_type **__ptr)
   1.644 +  { return __ptr; }
   1.645 +  static value_type & to_value_type_ref(storage_type &__ref)
   1.646 +  { return __ref; }
   1.647 +  static value_type const& to_value_type_cref(storage_type const&__ref)
   1.648 +  { return __ref; }
   1.649 +  // Reverse versions
   1.650 +  static storage_type * to_storage_type_ptr(value_type *__ptr)
   1.651 +  { return __ptr; }
   1.652 +  static storage_type const* to_storage_type_cptr(value_type const*__ptr)
   1.653 +  { return __ptr; }
   1.654 +  static storage_type ** to_storage_type_pptr(value_type **__ptr)
   1.655 +  { return __ptr; }
   1.656 +  static storage_type const& to_storage_type_cref(value_type const& __ref)
   1.657 +  { return __ref; }
   1.658 +
   1.659 +  //Method used to treat set container template method extension
   1.660 +  template <class _Tp1>
   1.661 +  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
   1.662 +  { return __ref; }
   1.663 +};
   1.664 +
   1.665 +#define _STLP_USE_ITERATOR_WRAPPER
   1.666 +
   1.667 +template <class _StorageT, class _ValueT, class _Iterator>
   1.668 +struct _IteWrapper {
   1.669 +  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.670 +  typedef iterator_traits<_Iterator> _IteTraits;
   1.671 +
   1.672 +  typedef typename _IteTraits::iterator_category iterator_category;
   1.673 +  typedef _StorageT value_type;
   1.674 +  typedef typename _IteTraits::difference_type difference_type;
   1.675 +  typedef value_type* pointer;
   1.676 +  typedef value_type const& const_reference;
   1.677 +  //This wrapper won't be used for input so to avoid surprise
   1.678 +  //the reference type will be a const reference:
   1.679 +  typedef const_reference reference;
   1.680 +
   1.681 +  typedef _IteWrapper<_StorageT, _ValueT, _Iterator> _Self;
   1.682 +  typedef _Self _Ite;
   1.683 +
   1.684 +  _IteWrapper(_Iterator &__ite) : _M_ite(__ite) {}
   1.685 +
   1.686 +  const_reference operator*() const { return cast_traits::to_storage_type_cref(*_M_ite); }
   1.687 +
   1.688 +  _Self& operator= (_Self const& __rhs) {
   1.689 +    _M_ite = __rhs._M_ite;
   1.690 +    return *this;
   1.691 +  }
   1.692 +
   1.693 +  _Self& operator++() {
   1.694 +    ++_M_ite;
   1.695 +    return *this;
   1.696 +  }
   1.697 +
   1.698 +  _Self& operator--() {
   1.699 +    --_M_ite;
   1.700 +    return *this;
   1.701 +  }
   1.702 +
   1.703 +  _Self& operator += (difference_type __offset) {
   1.704 +    _M_ite += __offset;
   1.705 +    return *this;
   1.706 +  }
   1.707 +  difference_type operator -(_Self const& __other) const
   1.708 +  { return _M_ite - __other._M_ite; }
   1.709 +
   1.710 +  bool operator == (_Self const& __other) const
   1.711 +  { return _M_ite == __other._M_ite; }
   1.712 +
   1.713 +  bool operator != (_Self const& __other) const
   1.714 +  { return _M_ite != __other._M_ite; }
   1.715 +
   1.716 +  bool operator < (_Self const& __rhs) const
   1.717 +  { return _M_ite < __rhs._M_ite; }
   1.718 +
   1.719 +private:
   1.720 +  _Iterator _M_ite;
   1.721 +};
   1.722 +
   1.723 +template <class _Tp, class _Iterator>
   1.724 +struct _IteWrapper<_Tp, _Tp, _Iterator>
   1.725 +{ typedef _Iterator _Ite; };
   1.726 +
   1.727 +#else
   1.728 +
   1.729 +/*
   1.730 + * In this config the storage type is qualified in respect of the
   1.731 + * value_type qualification. Simple reinterpret_cast is enough.
   1.732 + */
   1.733 +template <class _StorageT, class _ValueT>
   1.734 +struct _CastTraits {
   1.735 +  typedef _StorageT storage_type;
   1.736 +  typedef _ValueT value_type;
   1.737 +
   1.738 +  static value_type * to_value_type_ptr(storage_type *__ptr)
   1.739 +  { return __REINTERPRET_CAST(value_type*, __ptr); }
   1.740 +  static value_type const* to_value_type_cptr(storage_type const*__ptr)
   1.741 +  { return __REINTERPRET_CAST(value_type const*, __ptr); }
   1.742 +  static value_type ** to_value_type_pptr(storage_type **__ptr)
   1.743 +  { return __REINTERPRET_CAST(value_type **, __ptr); }
   1.744 +  static value_type & to_value_type_ref(storage_type &__ref)
   1.745 +  { return __REINTERPRET_CAST(value_type&, __ref); }
   1.746 +  static value_type const& to_value_type_cref(storage_type const&__ref)
   1.747 +  { return __REINTERPRET_CAST(value_type const&, __ref); }
   1.748 +  // Reverse versions
   1.749 +  static storage_type * to_storage_type_ptr(value_type *__ptr)
   1.750 +  { return __REINTERPRET_CAST(storage_type*, __ptr); }
   1.751 +  static storage_type const* to_storage_type_cptr(value_type const*__ptr)
   1.752 +  { return __REINTERPRET_CAST(storage_type const*, __ptr); }
   1.753 +  static storage_type ** to_storage_type_pptr(value_type **__ptr)
   1.754 +  { return __REINTERPRET_CAST(storage_type **, __ptr); }
   1.755 +  static storage_type const& to_storage_type_cref(value_type const&__ref)
   1.756 +  { return __REINTERPRET_CAST(storage_type const&, __ref); }
   1.757 +  template <class _Tp1>
   1.758 +  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)
   1.759 +  { return __ref; }
   1.760 +};
   1.761 +
   1.762 +#endif
   1.763 +
   1.764 +//Wrapper functors:
   1.765 +template <class _StorageT, class _ValueT, class _UnaryPredicate>
   1.766 +struct _UnaryPredWrapper {
   1.767 +  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.768 +
   1.769 +  _UnaryPredWrapper (_UnaryPredicate const& __pred) : _M_pred(__pred) {}
   1.770 +
   1.771 +  bool operator () (_StorageT const& __ref) const
   1.772 +  { return _M_pred(cast_traits::to_value_type_cref(__ref)); }
   1.773 +
   1.774 +private:
   1.775 +  _UnaryPredicate _M_pred;
   1.776 +};
   1.777 +
   1.778 +template <class _StorageT, class _ValueT, class _BinaryPredicate>
   1.779 +struct _BinaryPredWrapper {
   1.780 +  typedef _CastTraits<_StorageT, _ValueT> cast_traits;
   1.781 +
   1.782 +  _BinaryPredWrapper () {}
   1.783 +  _BinaryPredWrapper (_BinaryPredicate const& __pred) : _M_pred(__pred) {}
   1.784 +
   1.785 +  _BinaryPredicate get_pred() const { return _M_pred; }
   1.786 +
   1.787 +  bool operator () (_StorageT const& __fst, _StorageT const& __snd) const
   1.788 +  { return _M_pred(cast_traits::to_value_type_cref(__fst), cast_traits::to_value_type_cref(__snd)); }
   1.789 +
   1.790 +  //Cast operator used to transparently access underlying predicate
   1.791 +  //in set::key_comp() method
   1.792 +  operator _BinaryPredicate() const
   1.793 +  { return _M_pred; }
   1.794 +
   1.795 +private:
   1.796 +  _BinaryPredicate _M_pred;
   1.797 +};
   1.798 +
   1.799 +_STLP_MOVE_TO_STD_NAMESPACE
   1.800 +
   1.801 +_STLP_END_NAMESPACE
   1.802 +
   1.803 +#endif /* _STLP_POINTERS_SPEC_TOOLS_H */