_tools.h

来自「stl的源码」· C头文件 代码 · 共 472 行 · 第 1/2 页

H
472
字号
  { return __CONST_CAST(void_type*, __ptr); }  static void_type const* uncv_cptr(void_cv_type const*__ptr)  { return __CONST_CAST(void_type const*, __ptr); }  static void_type** uncv_pptr(void_cv_type **__ptr)  { return __CONST_CAST(void_type**, __ptr); }  static void_type& uncv_ref(void_cv_type &__ref)  { return __CONST_CAST(void_type&, __ref); }  static void_type const& uncv_cref(void_cv_type const& __ptr)  { return __CONST_CAST(void_type const&, __ptr); }  // The reverse versions  static void_cv_type * cv_ptr(void_type *__ptr)  { return __CONST_CAST(void_cv_type *, __ptr); }  static void_cv_type const* cv_cptr(void_type const*__ptr)  { return __CONST_CAST(void_cv_type const*, __ptr); }  static void_cv_type ** cv_pptr(void_type **__ptr)  { return __CONST_CAST(void_cv_type**, __ptr); }  static void_cv_type & cv_ref(void_type &__ref)  { return __CONST_CAST(void_cv_type &, __ref); }  static void_cv_type const& cv_cref(void_type const& __ref)  { return __CONST_CAST(void_cv_type const&, __ref); }};_STLP_TEMPLATE_NULLstruct _VoidCastTraitsAux<void*, const void*> : _VoidCastTraitsAuxBase<void const>{};_STLP_TEMPLATE_NULLstruct _VoidCastTraitsAux<void*, volatile void*> : _VoidCastTraitsAuxBase<void volatile>{};_STLP_TEMPLATE_NULLstruct _VoidCastTraitsAux<void*, const volatile void*> : _VoidCastTraitsAuxBase<void const volatile>{};template <class _StorageT, class _ValueT>struct _CastTraits {  typedef _ValueT value_type;  typedef typename _StorageType<_ValueT>::_QualifiedType _QualifiedStorageT;  typedef _VoidCastTraitsAux<_StorageT, _QualifiedStorageT> cv_traits;  typedef typename cv_traits::void_type void_type;  typedef typename cv_traits::void_cv_type void_cv_type;  static value_type * to_value_type_ptr(void_type *__ptr)  { return __REINTERPRET_CAST(value_type *, cv_traits::cv_ptr(__ptr)); }  static value_type const* to_value_type_cptr(void_type const*__ptr)  { return __REINTERPRET_CAST(value_type const*, cv_traits::cv_cptr(__ptr)); }  static value_type ** to_value_type_pptr(void_type **__ptr)  { return __REINTERPRET_CAST(value_type **, cv_traits::cv_pptr(__ptr)); }  static value_type & to_value_type_ref(void_type &__ref)  { return __REINTERPRET_CAST(value_type &, cv_traits::cv_ref(__ref)); }  static value_type const& to_value_type_cref(void_type const& __ptr)  { return __REINTERPRET_CAST(value_type const&, cv_traits::cv_cref(__ptr)); }  // Reverse versions  static void_type * to_storage_type_ptr(value_type *__ptr)  { return cv_traits::uncv_ptr(__REINTERPRET_CAST(void_cv_type *, __ptr)); }  static void_type const* to_storage_type_cptr(value_type const*__ptr)  { return cv_traits::uncv_cptr(__REINTERPRET_CAST(void_cv_type const*, __ptr)); }  static void_type ** to_storage_type_pptr(value_type **__ptr)  { return cv_traits::uncv_pptr(__REINTERPRET_CAST(void_cv_type **, __ptr)); }  static void_type const& to_storage_type_cref(value_type const& __ref)  { return cv_traits::uncv_cref(__REINTERPRET_CAST(void_cv_type const&, __ref)); }  //Method used to treat set container template method extension  static void_type const& to_storage_type_crefT(value_type const& __ref)  { return to_storage_type_cref(__ref); }};template <class _Tp>struct _CastTraits<_Tp, _Tp> {  typedef _Tp storage_type;  typedef _Tp value_type;  static value_type * to_value_type_ptr(storage_type *__ptr)  { return __ptr; }  static value_type const* to_value_type_cptr(storage_type const*__ptr)  { return __ptr; }  static value_type ** to_value_type_pptr(storage_type **__ptr)  { return __ptr; }  static value_type & to_value_type_ref(storage_type &__ref)  { return __ref; }  static value_type const& to_value_type_cref(storage_type const&__ref)  { return __ref; }  // Reverse versions  static storage_type * to_storage_type_ptr(value_type *__ptr)  { return __ptr; }  static storage_type const* to_storage_type_cptr(value_type const*__ptr)  { return __ptr; }  static storage_type ** to_storage_type_pptr(value_type **__ptr)  { return __ptr; }  static storage_type const& to_storage_type_cref(value_type const& __ref)  { return __ref; }  //Method used to treat set container template method extension  template <class _Tp1>  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)  { return __ref; }};#define _STLP_USE_ITERATOR_WRAPPERtemplate <class _StorageT, class _ValueT, class _Iterator>struct _IteWrapper {  typedef _CastTraits<_StorageT, _ValueT> cast_traits;  typedef iterator_traits<_Iterator> _IteTraits;  typedef typename _IteTraits::iterator_category iterator_category;  typedef _StorageT value_type;  typedef typename _IteTraits::difference_type difference_type;  typedef value_type* pointer;  typedef value_type const& const_reference;  //This wrapper won't be used for input so to avoid surprise  //the reference type will be a const reference:  typedef const_reference reference;  typedef _IteWrapper<_StorageT, _ValueT, _Iterator> _Self;  typedef _Self _Ite;  _IteWrapper(_Iterator &__ite) : _M_ite(__ite) {}  const_reference operator*() const { return cast_traits::to_storage_type_cref(*_M_ite); }  _Self& operator= (_Self const& __rhs) {    _M_ite = __rhs._M_ite;    return *this;  }  _Self& operator++() {    ++_M_ite;    return *this;  }  _Self& operator--() {    --_M_ite;    return *this;  }  _Self& operator += (difference_type __offset) {    _M_ite += __offset;    return *this;  }  difference_type operator -(_Self const& __other) const  { return _M_ite - __other._M_ite; }  bool operator == (_Self const& __other) const  { return _M_ite == __other._M_ite; }  bool operator != (_Self const& __other) const  { return _M_ite != __other._M_ite; }  bool operator < (_Self const& __rhs) const  { return _M_ite < __rhs._M_ite; }private:  _Iterator _M_ite;};template <class _Tp, class _Iterator>struct _IteWrapper<_Tp, _Tp, _Iterator>{ typedef _Iterator _Ite; };#else/* * In this config the storage type is qualified in respect of the * value_type qualification. Simple reinterpret_cast is enough. */template <class _StorageT, class _ValueT>struct _CastTraits {  typedef _StorageT storage_type;  typedef _ValueT value_type;  static value_type * to_value_type_ptr(storage_type *__ptr)  { return __REINTERPRET_CAST(value_type*, __ptr); }  static value_type const* to_value_type_cptr(storage_type const*__ptr)  { return __REINTERPRET_CAST(value_type const*, __ptr); }  static value_type ** to_value_type_pptr(storage_type **__ptr)  { return __REINTERPRET_CAST(value_type **, __ptr); }  static value_type & to_value_type_ref(storage_type &__ref)  { return __REINTERPRET_CAST(value_type&, __ref); }  static value_type const& to_value_type_cref(storage_type const&__ref)  { return __REINTERPRET_CAST(value_type const&, __ref); }  // Reverse versions  static storage_type * to_storage_type_ptr(value_type *__ptr)  { return __REINTERPRET_CAST(storage_type*, __ptr); }  static storage_type const* to_storage_type_cptr(value_type const*__ptr)  { return __REINTERPRET_CAST(storage_type const*, __ptr); }  static storage_type ** to_storage_type_pptr(value_type **__ptr)  { return __REINTERPRET_CAST(storage_type **, __ptr); }  static storage_type const& to_storage_type_cref(value_type const&__ref)  { return __REINTERPRET_CAST(storage_type const&, __ref); }  template <class _Tp1>  static _Tp1 const& to_storage_type_crefT(_Tp1 const& __ref)  { return __ref; }};#endif//Wrapper functors:template <class _StorageT, class _ValueT, class _UnaryPredicate>struct _UnaryPredWrapper {  typedef _CastTraits<_StorageT, _ValueT> cast_traits;  _UnaryPredWrapper (_UnaryPredicate const& __pred) : _M_pred(__pred) {}  bool operator () (_StorageT const& __ref) const  { return _M_pred(cast_traits::to_value_type_cref(__ref)); }private:  _UnaryPredicate _M_pred;};template <class _StorageT, class _ValueT, class _BinaryPredicate>struct _BinaryPredWrapper {  typedef _CastTraits<_StorageT, _ValueT> cast_traits;  _BinaryPredWrapper () {}  _BinaryPredWrapper (_BinaryPredicate const& __pred) : _M_pred(__pred) {}  _BinaryPredicate get_pred() const { return _M_pred; }  bool operator () (_StorageT const& __fst, _StorageT const& __snd) const  { return _M_pred(cast_traits::to_value_type_cref(__fst), cast_traits::to_value_type_cref(__snd)); }  //Cast operator used to transparently access underlying predicate  //in set::key_comp() method  operator _BinaryPredicate() const  { return _M_pred; }private:  _BinaryPredicate _M_pred;};_STLP_MOVE_TO_STD_NAMESPACE_STLP_END_NAMESPACE#endif /* _STLP_POINTERS_SPEC_TOOLS_H */

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?