?? stl_alloc.h
字號:
// Comparison operators for all of the predifined SGI-style allocators.
// This ensures that __allocator<malloc_alloc> (for example) will
// work correctly.
#ifndef __STL_NON_TYPE_TMPL_PARAM_BUG
template <int inst>
inline bool operator==(const __malloc_alloc<inst>&,
const __malloc_alloc<inst>&)
{
return true;
}
#ifdef __STL_FUNCTION_TMPL_PARTIAL_ORDER
template <int __inst>
inline bool operator!=(const __malloc_alloc<__inst>&,
const __malloc_alloc<__inst>&)
{
return false;
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
template <bool __threads, int __inst>
inline bool operator==(const __node_alloc<__threads, __inst>&,
const __node_alloc<__threads, __inst>&)
{
return true;
}
#if defined( __STL_FUNCTION_TMPL_PARTIAL_ORDER )
template <bool __threads, int __inst>
inline bool operator!=(const __node_alloc<__threads, __inst>&,
const __node_alloc<__threads, __inst>&)
{
return false;
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#endif /* __STL_NON_TYPE_TMPL_PARAM_BUG */
# ifdef __STL_DEBUG_ALLOC
template <class _Alloc>
inline bool operator==(const __debug_alloc<_Alloc>&,
const __debug_alloc<_Alloc>&) {
return true;
}
#ifdef __STL_USE_SEPARATE_RELOPS_NAMESPACE
template <class _Alloc>
inline bool operator!=(const __debug_alloc<_Alloc>&,
const __debug_alloc<_Alloc>&) {
return false;
}
#endif /* __STL_FUNCTION_TMPL_PARTIAL_ORDER */
#endif /* __STL_DEBUG_ALLOC */
// Another allocator adaptor: _Alloc_traits. This serves two
// purposes. First, make it possible to write containers that can use
// either SGI-style allocators or standard-conforming allocator.
// Second, provide a mechanism so that containers can query whether or
// not the allocator has distinct instances. If not, the container
// can avoid wasting a word of memory to store an empty object.
// This adaptor uses partial specialization. The general case of
// _Alloc_traits<_Tp, _Alloc> assumes that _Alloc is a
// standard-conforming allocator, possibly with non-equal instances
// and non-static members. (It still behaves correctly even if _Alloc
// has static member and if all instances are equal. Refinements
// affect performance, not correctness.)
// The fully general version.
// fbp: _S_instanceless is unused in STLport
// _Alloc_type is always being used to do allocation/deallocation
// allocator_type is the type being converted to _Allocator when returned
// from Container::get_allocator, unless it is NOT a raw alloc, in which case
// __get_alloc will return __allocator
template <class _Tp, class _Allocator>
struct _Alloc_traits
{
# if defined (__STL_MEMBER_TEMPLATE_CLASSES)
typedef typename _Allocator::__STL_TEMPLATE rebind<_Tp> _Rebind_type;
typedef typename _Rebind_type::other allocator_type;
# else
// this is not actually true, used only to pass this type through
// to dynamic overload selection in _STL_alloc_proxy methods
typedef _Allocator allocator_type;
# endif
};
#if defined (__STL_CLASS_PARTIAL_SPECIALIZATION)
// The version for the default allocator.
template <class _Tp, class _Tp1>
struct _Alloc_traits<_Tp, allocator<_Tp1> > {
typedef allocator<_Tp> allocator_type;
};
// Versions for the predefined SGI-style allocators.
template <class _Tp, int __inst>
struct _Alloc_traits<_Tp, __malloc_alloc<__inst> > {
typedef __allocator<_Tp, __malloc_alloc<__inst> > allocator_type;
};
template <class _Tp, bool __threads, int __inst>
struct _Alloc_traits<_Tp, __node_alloc<__threads, __inst> > {
typedef __allocator<_Tp, __node_alloc<__threads, __inst> >
allocator_type;
};
# ifdef __STL_DEBUG_ALLOC
template <class _Tp, class _Alloc>
struct _Alloc_traits<_Tp, __debug_alloc<_Alloc> > {
typedef __allocator<_Tp, __debug_alloc<_Alloc> > allocator_type;
};
# endif
// Versions for the __allocator adaptor used with the predefined
// SGI-style allocators.
template <class _Tp, class _Tp1, class _Alloc>
struct _Alloc_traits<_Tp, __allocator<_Tp1, _Alloc > > {
typedef __allocator<_Tp, _Alloc > allocator_type;
};
#endif /* __STL_CLASS_PARTIAL_SPECIALIZATION */
// this extension is used only for Apple workaround now
template <class _All>
struct _STL_factory {
static _All _Instance() { return _All(); }
};
#if defined (__STL_MEMBER_TEMPLATE_CLASSES)
// __a may be not rebound, return different type
template <class _Tp, class _Alloc>
inline __STL_TYPENAME_ON_RETURN_TYPE _Alloc_traits<_Tp, _Alloc>::allocator_type
__stl_alloc_create(const _Alloc& __a, const _Tp*) {
typedef _Alloc_traits<_Tp, _Alloc>::allocator_type _Rebound_type;
return _Rebound_type(__a);
}
#else
// Versions for the predefined SGI-style allocators.
template <class _Tp>
inline __allocator<_Tp, __new_alloc >
__stl_alloc_create(const __new_alloc&, const _Tp*) {
return __allocator<_Tp, __new_alloc >();
}
template <class _Tp>
inline __allocator<_Tp, __new_alloc >&
__stl_alloc_rebind(__new_alloc& __a, const _Tp*) {
return (__allocator<_Tp, __new_alloc >&)__a;
}
# if defined (__STL_DEBUG_ALLOC)
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> >
__stl_alloc_create(const __debug_alloc<_Alloc>&, const _Tp*) {
return __allocator<_Tp, __debug_alloc<_Alloc> >();
}
template <class _Tp, class _Alloc>
inline __allocator<_Tp, __debug_alloc<_Alloc> >&
__stl_alloc_rebind(__debug_alloc<_Alloc>& __a, const _Tp*) {
return (__allocator<_Tp, __debug_alloc<_Alloc> >&)__a;
}
# endif
# if defined (__STL_NON_TYPE_TMPL_PARAM_BUG)
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc<0> >&
__stl_alloc_rebind(__malloc_alloc<0>& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc<0> >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __node_alloc<false, 0> >&
__stl_alloc_rebind(__node_alloc<false, 0>& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc<false, 0> >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __node_alloc<true,0> >&
__stl_alloc_rebind(__node_alloc<true,0>& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc<true,0> >&)__a;
}
template <class _Tp>
inline __allocator<_Tp, __malloc_alloc<0> >
__stl_alloc_create(const __malloc_alloc<0>&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc<0> > ();
}
template <class _Tp>
inline __allocator<_Tp, __node_alloc<false, 0> >
__stl_alloc_create(const __node_alloc<false, 0>&, const _Tp*) {
return __allocator<_Tp, __node_alloc<false, 0> >();
}
template <class _Tp>
inline __allocator<_Tp, __node_alloc<true,0> >
__stl_alloc_create(const __node_alloc<true,0>&, const _Tp*) {
return __allocator<_Tp, __node_alloc<true,0> >();
}
# else
template <class _Tp, int __inst>
inline __allocator<_Tp, __malloc_alloc<__inst> >&
__stl_alloc_rebind(__malloc_alloc<__inst>& __a, const _Tp*) {
return (__allocator<_Tp, __malloc_alloc<__inst> >&)__a;
}
template <class _Tp, bool __threads, int __inst>
inline __allocator<_Tp, __node_alloc<__threads, __inst> >&
__stl_alloc_rebind(__node_alloc<__threads, __inst>& __a, const _Tp*) {
return (__allocator<_Tp, __node_alloc<__threads, __inst> >&)__a;
}
template <class _Tp, int __inst>
inline __allocator<_Tp, __malloc_alloc<__inst> >
__stl_alloc_create(const __malloc_alloc<__inst>&, const _Tp*) {
return __allocator<_Tp, __malloc_alloc<__inst> >();
}
template <class _Tp, bool __threads, int __inst>
inline __allocator<_Tp, __node_alloc<__threads, __inst> >
__stl_alloc_create(const __node_alloc<__threads, __inst>&, const _Tp*) {
return __allocator<_Tp, __node_alloc<__threads, __inst> >();
}
# endif
// If custom allocators are being used without member template classes support :
// user (on purpose) is forced to define rebind/get operations !!!
template <class _Tp1, class _Tp2>
inline allocator<_Tp2>&
__stl_alloc_rebind(allocator<_Tp1>& __a, const _Tp2*) {
return (allocator<_Tp2>&)(__a);
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc>&
__stl_alloc_rebind(__allocator<_Tp1, _Alloc>& __a, const _Tp2*) {
return (__allocator<_Tp2, _Alloc>&)__a;
}
template <class _Tp1, class _Tp2>
inline allocator<_Tp2>
__stl_alloc_create(const allocator<_Tp1>&, const _Tp2*) {
return allocator<_Tp2>();
}
template <class _Tp1, class _Alloc, class _Tp2>
inline __allocator<_Tp2, _Alloc>
__stl_alloc_create(const __allocator<_Tp1, _Alloc>&, const _Tp2*) {
return __allocator<_Tp2, _Alloc>();
}
#endif
// inheritance is being used for empty base
// class optimization
template <class _Value, class _Tp, class _MaybeReboundAlloc>
class _STL_alloc_proxy : public _MaybeReboundAlloc {
private:
typedef _MaybeReboundAlloc _Base;
typedef _STL_alloc_proxy<_Value, _Tp, _MaybeReboundAlloc> _Self;
public:
_Value _M_data;
// construction/destruction
_STL_alloc_proxy(const _Self& __x) : _MaybeReboundAlloc(__x), _M_data(__x._M_data) {}
_STL_alloc_proxy(const _MaybeReboundAlloc& __a, const _Value& __p) : _MaybeReboundAlloc(__a),
_M_data(__p) {}
_Self& operator = (const _Self& __x) { _M_data = __x._M_data; return *this; }
// _Self& operator = (const _Value& __x) { _M_data = __x; return *this; }
_Self& operator = (const _Base& __x) { ((_Base&)*this) = __x; return *this; }
// operator _Value() const { return _M_data; }
// Unified interface to perform allocate()/deallocate() with limited
// language support
#if defined (__STL_MEMBER_TEMPLATE_CLASSES)
# ifdef __BORLANDC__
_Tp* allocate(size_t __n) {
return _Base::allocate(__n);
}
# else
__STL_USING_BASE_MEMBER _MaybeReboundAlloc::allocate;
# endif
#else
// else it is rebound already, and allocate() member is accessible
_Tp* allocate(size_t __n) {
return __stl_alloc_rebind(__STATIC_CAST(_Base&,*this),(_Tp*)0).allocate(__n);
}
void deallocate(_Tp* __p, size_t __n) {
__stl_alloc_rebind(__STATIC_CAST(_Base&, *this),(_Tp*)0).deallocate(__p, __n);
}
#endif
};
__STL_END_NAMESPACE
# undef _S_FREELIST_INDEX
#if defined(__sgi) && !defined(__GNUC__) && (_MIPS_SIM != _MIPS_SIM_ABI32)
#pragma reset woff 1174
#endif
#if defined(__IBMCPP__)
#pragma info(restore)
#endif
# if !defined (__STL_LINK_TIME_INSTANTIATION)
# include <stl_alloc.c>
# endif
#endif /* __SGI_STL_INTERNAL_ALLOC_H */
// Local Variables:
// mode:C++
// End:
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -