📄 xutility
字号:
// xutility internal header
#pragma once
#ifndef _XUTILITY_
#define _XUTILITY_
#ifndef RC_INVOKED
#include <climits>
#include <cstdlib>
#include <utility>
#pragma pack(push,_CRT_PACKING)
#pragma warning(push,3)
_STD_BEGIN
// MACRO DEBUG_ERROR
#if _ITERATOR_DEBUG_LEVEL == 2
#define _DEBUG_ERROR(mesg) \
_DEBUG_ERROR2(mesg, __FILEW__, __LINE__)
#define _DEBUG_ERROR2(mesg, file, line) \
_Debug_message(L ## mesg, file, line)
typedef const wchar_t *_Dbfile_t;
typedef unsigned int _Dbline_t;
_CRTIMP2_PURE void __CLRCALL_PURE_OR_CDECL _Debug_message(const wchar_t *,
const wchar_t *, unsigned int);
#else /* _ITERATOR_DEBUG_LEVEL == 2 */
#define _DEBUG_ERROR(mesg)
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
// CLASSES _Container_base*, _Iterator_base*
struct _CRTIMP2_PURE _Container_base0
{ // base of all containers
void _Orphan_all()
{ // orphan all iterators
}
void _Swap_all(_Container_base0&)
{ // swap all iterators
}
};
struct _Iterator_base0
{ // base of all iterators
void _Adopt(const void *)
{ // adopt this iterator by parent
}
const _Container_base0 *_Getcont() const
{ // get owning container
return (0);
}
};
struct _Container_base12;
struct _Iterator_base12;
// CLASS _Container_proxy
struct _Container_proxy
{ // store head of iterator chain and back pointer
_Container_proxy()
: _Mycont(0), _Myfirstiter(0)
{ // construct from pointers
}
const _Container_base12 *_Mycont;
_Iterator_base12 *_Myfirstiter;
};
struct _CRTIMP2_PURE _Container_base12
{ // store pointer to _Container_proxy
public:
_Container_base12()
: _Myproxy(0)
{ // construct childless container
}
_Container_base12(const _Container_base12&)
: _Myproxy(0)
{ // copy a container
}
_Container_base12& operator=(const _Container_base12&)
{ // assign a container
return (*this);
}
~_Container_base12()
{ // destroy the container
_Orphan_all();
}
_Iterator_base12 **_Getpfirst() const
{ // get address of iterator chain
return (_Myproxy == 0 ? 0 : &_Myproxy->_Myfirstiter);
}
void _Orphan_all(); // orphan all iterators
void _Swap_all(_Container_base12&); // swap all iterators
_Container_proxy *_Myproxy;
};
struct _Iterator_base12
{ // store links to container proxy, next iterator
public:
_Iterator_base12()
: _Myproxy(0), _Mynextiter(0)
{ // construct orphaned iterator
}
_Iterator_base12(const _Iterator_base12& _Right)
: _Myproxy(0), _Mynextiter(0)
{ // copy an iterator
*this = _Right;
}
_Iterator_base12& operator=(const _Iterator_base12& _Right)
{ // assign an iterator
if (_Myproxy != _Right._Myproxy)
_Adopt(_Right._Myproxy->_Mycont);
return (*this);
}
~_Iterator_base12()
{ // destroy the iterator
#if _ITERATOR_DEBUG_LEVEL == 2
_Lockit _Lock(_LOCK_DEBUG);
_Orphan_me();
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
void _Adopt(const _Container_base12 *_Parent)
{ // adopt this iterator by parent
if (_Parent != 0)
{ // have a parent, do adoption
_Container_proxy *_Parent_proxy = _Parent->_Myproxy;
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != _Parent_proxy)
{ // change parentage
_Lockit _Lock(_LOCK_DEBUG);
_Orphan_me();
_Mynextiter = _Parent_proxy->_Myfirstiter;
_Parent_proxy->_Myfirstiter = this;
_Myproxy = _Parent_proxy;
}
#else /* _ITERATOR_DEBUG_LEVEL == 2 */
_Myproxy = _Parent_proxy;
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
}
void _Clrcont()
{ // disown owning container
_Myproxy = 0;
}
const _Container_base12 *_Getcont() const
{ // get owning container
return (_Myproxy == 0 ? 0 : _Myproxy->_Mycont);
}
_Iterator_base12 **_Getpnext()
{ // get address of remaining iterator chain
return (&_Mynextiter);
}
void _Orphan_me()
{ // cut ties with parent
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != 0)
{ // adopted, remove self from list
_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
while (*_Pnext != 0 && *_Pnext != this)
_Pnext = &(*_Pnext)->_Mynextiter;
if (*_Pnext == 0)
_DEBUG_ERROR("ITERATOR LIST CORRUPTED!");
*_Pnext = _Mynextiter;
_Myproxy = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
_Container_proxy *_Myproxy;
_Iterator_base12 *_Mynextiter;
};
// MEMBER FUNCTIONS FOR _Container_base12
inline void _Container_base12::_Orphan_all()
{ // orphan all iterators
#if _ITERATOR_DEBUG_LEVEL == 2
if (_Myproxy != 0)
{ // proxy allocated, drain it
_Lockit _Lock(_LOCK_DEBUG);
for (_Iterator_base12 **_Pnext = &_Myproxy->_Myfirstiter;
*_Pnext != 0; *_Pnext = (*_Pnext)->_Mynextiter)
(*_Pnext)->_Myproxy = 0;
_Myproxy->_Myfirstiter = 0;
}
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
}
inline void _Container_base12::_Swap_all(_Container_base12& _Right)
{ // swap all iterators
#if _ITERATOR_DEBUG_LEVEL == 2
_Lockit _Lock(_LOCK_DEBUG);
#endif /* _ITERATOR_DEBUG_LEVEL == 2 */
_Container_proxy *_Temp = _Myproxy;
_Myproxy = _Right._Myproxy;
_Right._Myproxy = _Temp;
if (_Myproxy != 0)
_Myproxy->_Mycont = (_Container_base12 *)this;
if (_Right._Myproxy != 0)
_Right._Myproxy->_Mycont = (_Container_base12 *)&_Right;
}
#if _ITERATOR_DEBUG_LEVEL == 0
typedef _Container_base0 _Container_base;
typedef _Iterator_base0 _Iterator_base;
#else /* _ITERATOR_DEBUG_LEVEL == 0 */
typedef _Container_base12 _Container_base;
typedef _Iterator_base12 _Iterator_base;
#endif /* _ITERATOR_DEBUG_LEVEL == 0 */
// TEMPLATE FUNCTION _Has_unchecked_type AND FRIENDS
#define _UNCHECKED_TYPE(_Iter) \
typename _Get_unchecked_type<_Iter>::type
_STD tr1::_No _Has_unchecked_type(...);
template<class _Ty>
_STD tr1::_Yes _Has_unchecked_type(_Ty *,
typename _Ty::_Unchecked_type * = 0);
template<class _Iter,
bool>
struct _Unchecked_helper
{ // _Iter doesn't define _Unchecked_type
typedef _Iter type;
};
template<class _Iter>
struct _Unchecked_helper<_Iter, true>
{ // _Iter defines _Unchecked_type
typedef typename _Iter::_Unchecked_type type;
};
template<class _Iter>
struct _Get_unchecked_type
{ // wraps unchecked type
typedef typename _Unchecked_helper<_Iter,
_IS_YES(_Has_unchecked_type((_Iter *)0))>::type type;
};
// TEMPLATE FUNCTION _Unchecked
template<class _Iter> inline
_Iter _Unchecked(_Iter _Src)
{ // construct unchecked from checked, generic
return (_Src);
}
// TEMPLATE FUNCTION _Rechecked
template<class _Iter,
class _UIter> inline
_Iter& _Rechecked(_Iter& _Dest, _UIter _Src)
{ // reset checked from unchecked, generic
_Dest = _Src;
return (_Dest);
}
// TEMPLATE STRUCT _Is_checked_helper
template<class _Iter>
struct _Is_checked_helper
: public _STD tr1::integral_constant<bool, _IS_YES(_Has_unchecked_type((_Iter *)0))>
{ // determine whether _Iter is checked
};
// TEMPLATE FUNCTION _Is_checked
template<class _Iter> inline
_Is_checked_helper<_Iter> _Is_checked(_Iter)
{ // return type is derived from true_type if iterator is checked
return (_Is_checked_helper<_Iter>());
}
// ITERATOR STUFF (from <iterator>)
// ITERATOR TAGS
struct input_iterator_tag
{ // identifying tag for input iterators
};
struct output_iterator_tag
{ // identifying tag for output iterators
};
struct forward_iterator_tag
: public input_iterator_tag, output_iterator_tag
{ // identifying tag for forward iterators
};
struct bidirectional_iterator_tag
: public forward_iterator_tag
{ // identifying tag for bidirectional iterators
};
struct random_access_iterator_tag
: public bidirectional_iterator_tag
{ // identifying tag for random-access iterators
};
struct _Int_iterator_tag
{ // identifying tag for integer types, not an iterator
};
// POINTER ITERATOR TAGS
struct _Nonscalar_ptr_iterator_tag
{ // pointer to unknown type
};
struct _Scalar_ptr_iterator_tag
{ // pointer to scalar type
};
// TEMPLATE CLASS iterator
template<class _Category,
class _Ty,
class _Diff = ptrdiff_t,
class _Pointer = _Ty *,
class _Reference = _Ty&>
struct iterator
{ // base type for all iterator classes
typedef _Category iterator_category;
typedef _Ty value_type;
typedef _Diff difference_type;
typedef _Diff distance_type; // retained
typedef _Pointer pointer;
typedef _Reference reference;
};
template<class _Category,
class _Ty,
class _Diff,
class _Pointer,
class _Reference,
class _Base>
struct _Iterator012
: public _Base
{
typedef _Category iterator_category;
typedef _Ty value_type;
typedef _Diff difference_type;
typedef _Diff distance_type; // retained
typedef _Pointer pointer;
typedef _Reference reference;
};
struct _Outit
: public iterator<output_iterator_tag, void, void,
void, void>
{ // base for output iterators
};
// TEMPLATE CLASS iterator_traits
template<class _Iter>
struct iterator_traits
{ // get traits from iterator _Iter
typedef typename _Iter::iterator_category iterator_category;
typedef typename _Iter::value_type value_type;
typedef typename _Iter::difference_type difference_type;
typedef difference_type distance_type; // retained
typedef typename _Iter::pointer pointer;
typedef typename _Iter::reference reference;
};
template<class _Ty>
struct iterator_traits<_Ty *>
{ // get traits from pointer
typedef random_access_iterator_tag iterator_category;
typedef _Ty value_type;
typedef ptrdiff_t difference_type;
typedef ptrdiff_t distance_type; // retained
typedef _Ty *pointer;
typedef _Ty& reference;
};
template<class _Ty>
struct iterator_traits<const _Ty *>
{ // get traits from const pointer
typedef random_access_iterator_tag iterator_category;
typedef _Ty value_type;
typedef ptrdiff_t difference_type;
typedef ptrdiff_t distance_type; // retained
typedef const _Ty *pointer;
typedef const _Ty& reference;
};
template<> struct iterator_traits<_Bool>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<char>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<signed char>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<unsigned char>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
#ifdef _NATIVE_WCHAR_T_DEFINED
template<> struct iterator_traits<wchar_t>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
#endif /* _NATIVE_WCHAR_T_DEFINED */
template<> struct iterator_traits<short>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<unsigned short>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<int>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<unsigned int>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<long>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<unsigned long>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
#ifdef _LONGLONG
template<> struct iterator_traits<_LONGLONG>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
template<> struct iterator_traits<_ULONGLONG>
{ // get traits from integer type
typedef _Int_iterator_tag iterator_category;
};
#endif /* _LONGLONG */
// TEMPLATE FUNCTION _Iter_cat
template<class _Iter> inline
typename iterator_traits<_Iter>::iterator_category
_Iter_cat(const _Iter&)
{ // return category from iterator argument
typename iterator_traits<_Iter>::iterator_category _Cat;
return (_Cat);
}
// TEMPLATE FUNCTION _Ptr_cat
template<class _Iter1,
class _Iter2> inline
_Nonscalar_ptr_iterator_tag _Ptr_cat(_Iter1&, _Iter2&)
{ // return pointer category from arbitrary arguments
_Nonscalar_ptr_iterator_tag _Cat;
return (_Cat);
}
template<class _Elem1,
class _Elem2>
struct _Ptr_cat_helper
{ // determines pointer category, nonscalar by default
typedef _Nonscalar_ptr_iterator_tag _Type;
};
template<class _Elem>
struct _Ptr_cat_helper<_Elem, _Elem>
{ // determines pointer category, common type
typedef typename _STD tr1::conditional<
_STD tr1::is_scalar<_Elem>::value,
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -