⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memory

📁 realview22.rar
💻
📖 第 1 页 / 共 2 页
字号:
    }

    // 20.4.2, p7
    raw_storage_iterator operator++ (int) {
        raw_storage_iterator __tmp = *this;
        ++*this;
        return __tmp;
    }
};


_RWSTD_NAMESPACE_END   // std


_RWSTD_NAMESPACE_BEGIN (__rw)

// __rw_indestructible specializations should be objects with static
// storage duration that must "survive" all other static objects and that
// do not need to be destroyed; this is a POD
template <class _TypeT>
class __rw_indestructible
{
    union _C_data_t {
        char        _C_data;      // data to back _TypeT up with 
        long double _C_padding;   // make sure data is suitably aligned
    };

    enum { _C_n = 1 + sizeof (_TypeT) / sizeof (_C_data_t) };

    _C_data_t _C_data [_C_n];     // raw storage for an object of _TypeT

public:
    typedef _TypeT            value_type;
    typedef value_type&       reference;
    typedef const value_type& const_reference;
    typedef value_type*       pointer;
    typedef const value_type* const_pointer;

    // no ctor to allow static POD initialization (3.6.2, p1)

    // allow this to be used as a an obejct of another type
    operator reference () {
        return _RWSTD_REINTERPRET_CAST (reference, *_C_data);
    }

    operator const_reference () const {
        return _RWSTD_REINTERPRET_CAST (const_reference, *_C_data);
    }

    // calls a conversion operator above
    pointer operator& () {
        // deprecated C-style cast used to make SunPro 5.0/T9 happy
        // return &_RWSTD_STATIC_CAST (reference, *this);

        return &(reference)*this;
    }
    
    // calls a conversion operator above
    const_pointer operator& () const {
        // deprecated C-style cast used to make SunPro 5.0/T9 happy
        // return &_RWSTD_STATIC_CAST (const_reference, *this);

        return &(const_reference)*this;
    }
};


#ifdef _INLINE_WITH_STATICS

_INLINE_WITH_STATICS _RWSTD_EXPORT char* __rw_get_static_buf ()
{
    typedef char _CharBuf [_RWSTD_TMPBUF_SIZE + 1];

    // use `indestructible' to guarantee proper buffer alignment
    static __rw_indestructible<_CharBuf> __buffer;

    return _RWSTD_STATIC_CAST (char*, __buffer);
}


// [de]allocates a previously allocated temporary buffer
// the constant _RWSTD_TMPBUF_SIZE controls the size of a static buffer
// if request for area larger than _RWSTD_TMPBUF_SIZE comes in,
// space is allocated dynamically, otherwise the static buffer is used
// return value meaningful only if __n != 0
_INLINE_WITH_STATICS _RWSTD_EXPORT _STD::pair<void*, _RWSTD_C::size_t>
__rw_reallocate_temp_buffer (void *__p, _RWSTD_C::size_t __size)
{
    // implicit initialization used to prevent a g++ 2.95.2 warning on Tru64
    // sorry: semantics of inline function static data are wrong (you'll wind
    // up with multiple copies)

    static unsigned long __busy /* = 0 */;   // > 0 when buffer in use

    unsigned long __cntr = _RWSTD_ATOMIC_PREINCREMENT (__busy, false);

    static char *__buffer = __rw_get_static_buf ();

    if (__p == (void*)__buffer) {
        __p    = 0;
        __size = 0;

        // returning buffer, decrement usage counter
        _RWSTD_ATOMIC_PREDECREMENT (__busy, false);
    }
    else
        ::operator delete (__p);

    if (__size > _RWSTD_TMPBUF_SIZE || __cntr > 1) {
        _TRY {
            __p = ::operator new (__size);
        }
        _CATCH (...) {
            __p    = 0;
            __size = 0;
        }

        // buffer not used, decrement usage counter
        _RWSTD_ATOMIC_PREDECREMENT (__busy, false);
    }
    else {
        __p = __buffer;

        // buffer used, usage counter stays non-zero
    }

    return _STD::pair<void*, _RWSTD_C::size_t>(__p, __size);
}

#else   // if !defined (_INLINE_WITH_STATICS)

_STD::pair<void*, _RWSTD_C::size_t> _RWSTD_EXPORT
__rw_reallocate_temp_buffer (void*, _RWSTD_C::size_t);

#endif   // _INLINE_WITH_STATICS

_RWSTD_NAMESPACE_END   // __rw


_RWSTD_NAMESPACE_BEGIN (std)


// 20.4.3 only specifies a get_temporary_buffer<>() that takes a ptrdiff_t.
// We overload on all types so that signed integral types other than ptrdiff_t
// can be used. This is important in getting algorithms to compile with
// user-defined iterators (not derived from iterator<...>) whose difference
// type is something other than ptrdiff_t.

// having this overload is important in some cases for compilers that
// do not support partial class specialization (and where as a consequence
// iterator_traits<> isn't available)
template <class _TypeT, class _Distance>
inline pair<_TypeT*, _Distance> get_temporary_buffer (_Distance __n, _TypeT*)
{
    pair<void*, size_t> __pair =
        _RW::__rw_reallocate_temp_buffer (0, __n * sizeof (_TypeT));

    return make_pair (_RWSTD_STATIC_CAST (_TypeT*, __pair.first),
                      _Distance (__pair.second / sizeof (_TypeT)));
}


#ifndef _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE

// 20.4.3, p1
template <class _TypeT>
inline pair<_TypeT*, ptrdiff_t> get_temporary_buffer (ptrdiff_t __n)
{
    return get_temporary_buffer (__n, (_TypeT*)0);
}

#endif   // _RWSTD_NO_TEMPLATE_ON_RETURN_TYPE


// 20.4.3, p3
template <class _TypeT>
inline void return_temporary_buffer (_TypeT *__p)
{
    _RW::__rw_reallocate_temp_buffer (__p, 0);
}


// 20.4.4.1
template <class _InputIterator, class _ForwardIterator>
inline
_ForwardIterator uninitialized_copy (_InputIterator   __first,
                                     _InputIterator   __last,
                                     _ForwardIterator __res)
{
    _ForwardIterator __start = __res;

    _TRY {
        for (; __first != __last; ++__first, ++__res)
            _RW::__rw_construct (&*__res, *__first);
    }
    _CATCH (...) {
        _RW::__rw_destroy (__start, __res);
        _RETHROW;
    }

    return __res;
}


#ifdef _RWSTD_ALLOCATOR

// extension
template <class _InputIterator, class _ForwardIterator, class _Allocator>
inline
_ForwardIterator uninitialized_copy (_InputIterator   __first,
                                     _InputIterator   __last,
                                     _ForwardIterator __res,
                                     _Allocator&      __alloc)
{
    _ForwardIterator __start = __res;

    _TRY {
        for (; __first != __last; ++__first, ++__res)
            __alloc.construct (&*__res, *__first);
    }
    _CATCH (...) {
        for (; __start != __res; ++__start)
            __alloc.destroy (&*__start);
        _RETHROW;
    }

    return __res;
}

#endif   // _RWSTD_ALLOCATOR


// 20.4.4.2
template <class _ForwardIterator, class _TypeT>
inline
void uninitialized_fill (_ForwardIterator __first, _ForwardIterator __last,
                         const _TypeT& __x)
{
    _ForwardIterator __start = __first;

    _TRY {
        for (; __first != __last; ++__first)
            _RW::__rw_construct (&*__first, __x);
    }
    _CATCH (...) {
        _RW::__rw_destroy (__start, __first);
        _RETHROW;
    }
}


// 20.4.4.3
template <class _ForwardIterator, class _Size, class _TypeT>
inline
void uninitialized_fill_n (_ForwardIterator __first, _Size __n,
                           const _TypeT& __x)
{
    _ForwardIterator __start = __first;

    _TRY {
        for (; __n; --__n, ++__first)
            _RW::__rw_construct (&*__first, __x);
    }
    _CATCH (...) {
        _RW::__rw_destroy (__start, __first);
        _RETHROW;
    }
}


#ifdef _RWSTD_ALLOCATOR

// extension
template <class _ForwardIter, class _Size, class _TypeT, class _Allocator>
inline
void uninitialized_fill_n (_ForwardIter __first, _Size __n,
                           const _TypeT& __x, _Allocator& __alloc)
{
    _ForwardIter __start = __first;

    _TRY {
        for (; __n; --__n, ++__first)
            __alloc.construct (&*__first, __x);
    }
    _CATCH (...) {
        for (; __start != __first; ++__start)
            __alloc.destroy (&*__start);
        _RETHROW;
    }
}

#else   // if !defined (_RWSTD_ALLOCATOR)

// Specializations for non-standard allocators.  When vector calls
// uninitialized_{copy,fill_n} with non-standard allocator, a temporary
// instance of allocator_interface is passed to these functions.  Since
// C++ forbids temporaries to be passed as non-const references, we
// use these specializations to pass a const reference (and we can force
// allocator_interface members construct & destroy to be const).

template <class _InputIterator, class _ForwardIterator,
          class _Allocator, class _TypeT>
inline _ForwardIterator
uninitialized_copy (_InputIterator   __first,
                    _InputIterator   __last,
                    _ForwardIterator __res,
                    const allocator_interface<_Allocator, _TypeT>& __alloc)
{
    _ForwardIterator __start = __res;

    _TRY {
        for (; __first != __last; ++__first, ++__res)
            __alloc.construct (&*__res, *__first);
    }
    _CATCH (...) {
        for (; __start != __res; ++__start)
            __alloc.destroy (&*__start);
        _RETHROW;
    }

    return __res;
}

template <class _ForwardIter, class _Size,
          class _TypeT, class _Allocator, class _TypeU>
inline void
uninitialized_fill_n (_ForwardIter __first, _Size __n,
                      const _TypeT& __x,
                      const allocator_interface<_Allocator, _TypeU>& __alloc)
{
    _ForwardIter __start = __first;

    _TRY {
        for (; __n; --__n, ++__first)
            __alloc.construct (&*__first, __x);
    }
    _CATCH (...) {
        for (; __start != __first; ++__start)
            __alloc.destroy (&*__start);
        _RETHROW;
    }
}

#endif   // _RWSTD_ALLOCATOR


// 20.4.5 - Template class auto_ptr

template<class _TypeT>
class auto_ptr;


// 20.4.5, p2 (defined outside of auto_ptr<> according to the proposed
// resolution of lwg issue 127)
template <class _TypeT>
class auto_ptr_ref 
{
public:
    auto_ptr<_TypeT>& _C_ptr;

    auto_ptr_ref (auto_ptr<_TypeT>& __rhs) : _C_ptr (__rhs) { }
};


template<class _TypeT>
class auto_ptr
{
public:
    typedef _TypeT element_type;

    _EXPLICIT auto_ptr (element_type* __p = 0) _THROWS (())
     : _C_ptr (__p) { }

    auto_ptr (auto_ptr& __rhs) _THROWS (())
     : _C_ptr (__rhs.release ()) { }

    auto_ptr& operator= (auto_ptr& __rhs) _THROWS (()) { 
        reset (__rhs.release ());
        return *this;
    }

    // follows lwg issue 127
    auto_ptr&
    operator= (auto_ptr_ref<element_type> __rhs) _THROWS (()) {
        reset (__rhs._C_ptr.release ());
        return *this;
    }

#ifndef _RWSTD_NO_MEMBER_TEMPLATES

    template <class _TypeU>
    operator auto_ptr_ref<_TypeU>() _THROWS (()) {
        return auto_ptr_ref<_TypeU>(*this);
    }

    template <class _TypeU> 
    operator auto_ptr<_TypeU>() _THROWS (()) {
        return auto_ptr<_TypeU>(release ());
    }

    template <class _TypeU>
    auto_ptr (auto_ptr<_TypeU>& __rhs) _THROWS (())
    : _C_ptr (__rhs.release ()) { }

    template <class _TypeU>
    auto_ptr& operator= (auto_ptr<_TypeU>& __rhs)  _THROWS (()) { 
        reset (__rhs.release ());
        return *this;
    }

#endif   // _RWSTD_NO_MEMBER_TEMPLATES


    ~auto_ptr () _THROWS (()) {
        delete _C_ptr;
    }

    element_type* get () const _THROWS (()) {
        return _C_ptr;
    }

    element_type& operator* () const _THROWS (()) {
        _RWSTD_ASSERT (0 != get ());
        return *get (); 
    }

    _RWSTD_OPERATOR_ARROW (
        element_type* operator-> () const _THROWS (()))

    element_type* release () _THROWS (()) { 
        element_type* __tmp = _C_ptr;
        _C_ptr = 0;
        return __tmp; 
    }

    void reset (element_type* __p = 0) _THROWS (()) { 
        if (_C_ptr != __p) {
            delete _C_ptr;
            _C_ptr = __p;
        }
    }

    auto_ptr (auto_ptr_ref<element_type> __r) _THROWS (())
    : _C_ptr (__r._C_ptr.release ()) { }

private:
    element_type* _C_ptr;
};


_RWSTD_NAMESPACE_END   // std


#endif   // _RWSTD_MEMORY_INCLUDED

⌨️ 快捷键说明

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