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

📄 vector

📁 realview22.rar
💻
📖 第 1 页 / 共 4 页
字号:
    
    typedef bool const_reference;

    // hacks working around bogus g++ 2.95.2 warnings coming out of
    // iterators below as well as what's probably an MSVC 6.0 bug
    typedef reference       _C_ref;
    typedef const_reference _C_const_ref;
    typedef difference_type _C_diff_t;

    class _C_iter {
        friend class iterator;
        friend class const_iterator;

    protected:

#if defined (__GNUG__) && __GNUG__ == 2 && __GNUG_MINOR__ < 96
    public:
#elif defined (_MSC_VER) && _MSC_VER <= 1300
        friend class vector<bool, _Allocator>;
#elif defined(__arm)
    public:
#else
        friend class vector;
#endif
        unsigned int* _C_p;
        unsigned int  _C_offset;

        _C_iter (unsigned int* __x = 0, unsigned int __y = 0)
            : _C_p (__x), _C_offset (__y) { }

        void operator++ () {
            if (_C_offset++ == _RWSTD_WORD_BIT - 1) {
                _C_offset = 0; 
                ++_C_p;
            }
        }

        void operator-- () {
            if (_C_offset-- == 0) {
                _C_offset = _RWSTD_WORD_BIT - 1; 
                --_C_p;
            }
        }

        void operator+= (difference_type __i) {
            difference_type __n = __i + _C_offset;
            _C_p += __n / _RWSTD_WORD_BIT;
            __n = __n % _RWSTD_WORD_BIT;
            if (__n < 0) {
                _C_offset = _RWSTD_STATIC_CAST (unsigned int,
                                                __n + _RWSTD_WORD_BIT);
                --_C_p;
            }
            else
                _C_offset = _RWSTD_STATIC_CAST (unsigned int,__n);
        }

    public:

        bool operator== (const _C_iter& __x) const {
            return _C_p == __x._C_p && _C_offset == __x._C_offset;
        }

        bool operator< (const _C_iter& __x) const {
            return _C_p < __x._C_p ||
                (_C_p == __x._C_p && _C_offset < __x._C_offset);
        }

        bool operator!= (const _C_iter& __x) const {
            return !(*this == __x);
        }

        bool operator> (const _C_iter& __x) const {
            return __x < *this;
        }

        bool operator>= (const _C_iter& __x) const {
            return !(*this < __x);
        }

        bool operator<= (const _C_iter& __x) const {
            return !(*this > __x);
        }
    };
      
    class iterator
        : public _C_iter,
          public _STD::iterator<random_access_iterator_tag,
                                value_type, _C_diff_t,
                                pointer, _C_ref> {
    public:

        // bring names used in declarations below into scope
        // (dependent base members not visible without qualification)
        typedef _C_ref    reference;
        typedef _C_diff_t difference_type;

        iterator (unsigned int *__x = 0, unsigned int __y = 0)
            : _C_iter (__x, __y) { }

        reference operator* () const { 
            typedef reference _Reference;
            return _Reference (this->_C_p, 1U << this->_C_offset); 
        }

        iterator& operator++ () {
            return _C_iter::operator++(), *this;
        }

        iterator operator++ (int) {
            iterator __tmp = *this;
            ++*this;
            return __tmp;
        }

        iterator& operator-- () {
            return _C_iter::operator--(), *this;
        }

        iterator operator-- (int) {
            iterator __tmp = *this;
            --*this;
            return __tmp;
        }

        iterator& operator+= (difference_type __i) {
            return _C_iter::operator+= (__i), *this;
        }

        iterator& operator-= (difference_type __i) {
            *this += -__i;
            return *this;
        }

        iterator operator+ (difference_type __i) const {
            iterator __tmp = *this;
            return __tmp += __i;
        }

        iterator operator- (difference_type __i) const {
            iterator __tmp = *this;
            return __tmp -= __i;
        }

        difference_type operator- (iterator __x) const {
            return   _RWSTD_WORD_BIT * (this->_C_p - __x._C_p)
                   + this->_C_offset - __x._C_offset;
        }

        reference operator[] (difference_type __i) {
            return *(*this + __i);
        }
    };

    class const_iterator
        : public _C_iter,
          public _STD::iterator<random_access_iterator_tag,
                                value_type, _C_diff_t,
                                const_pointer, _C_const_ref> {
    public:

        // bring names used in declarations below into scope
        // (dependent base members not visible without qualification)
        typedef _C_const_ref const_reference;
        typedef _C_diff_t    difference_type;

        const_iterator (unsigned int *__x = 0, unsigned int __y = 0)
            : _C_iter (__x, __y) { }

        const_iterator (const _C_iter &__x)
            : _C_iter (__x._C_p, __x._C_offset) { }

        const_reference operator* () const {
            return _C_ref (this->_C_p, 1U << this->_C_offset);
        }

        const_iterator& operator++ () {
            return _C_iter::operator++(), *this;
        }

        const_iterator operator++ (int) {
            const_iterator __tmp = *this;
            ++*this;
            return __tmp;
        }

        const_iterator& operator-- () {
            return _C_iter::operator--(), *this;
        }

        const_iterator operator-- (int) {
            const_iterator __tmp = *this;
            --*this;
            return __tmp;
        }

        const_iterator& operator+= (difference_type __i) {
            return _C_iter::operator+= (__i), *this;
        }

        const_iterator& operator-= (difference_type __i) {
            return *this += -__i;
        }

        const_iterator
        operator+ (difference_type __i) const {
            return const_iterator (*this) += __i;
        }

        const_iterator operator- (difference_type __i) const {
            return const_iterator (*this) -= __i;
        }

        difference_type operator- (const_iterator __x) const {
            return   _RWSTD_WORD_BIT * (this->_C_p - __x._C_p)
                   + this->_C_offset - __x._C_offset;
        }

        const_reference operator[] (difference_type __i) { 
            return *(*this + __i); 
        }
    };

#ifndef _RWSTD_NO_CLASS_PARTIAL_SPEC 

    typedef _STD::reverse_iterator<const_iterator> const_reverse_iterator;
    typedef _STD::reverse_iterator<iterator>       reverse_iterator;

#else

    typedef _STD::reverse_iterator<const_iterator, 
        random_access_iterator_tag, value_type, 
        const_reference, const_pointer, difference_type>
    const_reverse_iterator;

    typedef _STD::reverse_iterator<iterator, 
        random_access_iterator_tag, value_type,
        reference, pointer, difference_type>
    reverse_iterator;

#endif   // _RWSTD_NO_CLASS_PARTIAL_SPEC 

  private:
    //
    // These private functions are replicas of generic algorithms.
    //  We provide them here to avoid putting instantiations of 
    //  the generic algorithms into an archive or shared library.
    //  This gives you full flexibilty in deciding where you want
    //  to put particular instantiations of the generic 
    //  algorithms.
    //
  
    void _C_fill (iterator __first, iterator __last, const bool& __value) {
        while (__first != __last) *__first++ = __value;
    }

    void _C_fill_n (iterator __first, size_type __n, const bool& __value) {
        while (__n-- > 0) *__first++ = __value;
    }

#ifndef _RWSTD_NO_MEMBER_TEMPLATES

    template <class _Iterator>
    iterator _C_copy (_Iterator __first, _Iterator __last, iterator __res) {
        while (__first != __last)
            *__res++ = *__first++;
        return __res;
    }

    template <class _Iterator>
    iterator
    _C_copy_backward (_Iterator __first, _Iterator __last, iterator __res) {
        while (__first != __last) *--__res = *--__last;
        return __res;
    }

#else
    iterator
    _C_copy (const_iterator __first, const_iterator __last, iterator __res) {
        while (__first != __last)
            *__res++ = *__first++;
        return __res;
    }

    iterator _C_copy (const bool* __first, const bool* __last, iterator __res) {
        while (__first != __last)
            *__res++ = *__first++;
        return __res;
    }

    iterator _C_copy_backward (const_iterator __first, const_iterator __last,
                               iterator __res) {
        while (__first != __last)
            *--__res = *--__last;
        return __res;
    }

    iterator
    _C_copy_backward (const bool* __first, const bool* __last, iterator __res) {
        while (__first != __last)
            *--__res = *--__last;
        return __res;
    }

#endif

protected:

    iterator       _C_start;
    iterator       _C_finish;
    unsigned int * _C_end_of_storage;

    unsigned int* _C_bit_alloc (size_type __n) {
        return _C_value_alloc_type(*this).
            allocate ((__n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT,
                      pointer(_C_start._C_p));
    }

    void _C_init (size_type __n) {
        unsigned int* __q = _C_bit_alloc(__n);
        _C_end_of_storage = __q + (__n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
        _C_start = iterator(__q, 0);
        _C_finish = _C_start + __n;
    }

    void _C_insert_aux (iterator, bool);

public:

    vector (const _Allocator&  __alloc = allocator_type ())
      : allocator_type (__alloc), _C_start(iterator()), _C_finish(iterator()), 
        _C_end_of_storage(0) { }

    _EXPLICIT vector (size_type __n, bool __value = bool(), 
       const _Allocator&  __alloc = allocator_type ())
      : allocator_type (__alloc), _C_end_of_storage(0) {
      _C_init(__n); 
      unsigned int * __first = _C_start._C_p;
      size_type __m = (__n + _RWSTD_WORD_BIT - 1)/_RWSTD_WORD_BIT;
      while (__m-- > 0) *__first++ = __value ? ~0 : 0;
    }

    vector (const _C_self &__x)
        : allocator_type (__x.get_allocator ()), _C_end_of_storage (0) {
        _C_init (__x.size ()); 
        _C_copy (__x.begin (), __x.end (), _C_start);
    }

#ifndef _RWSTD_NO_MEMBER_TEMPLATES
    template<class _InputIter>
    vector  (_InputIter __first, _InputIter __last)
      : _C_end_of_storage(0)
    {
      size_type __n = _DISTANCE (__first, __last, size_type);
      _C_init(__n); 
      _C_copy(__first, __last, _C_start);
    }
#else
    vector (const_iterator __first, const_iterator __last)
      : _C_end_of_storage(0)
    {
      size_type __n = _DISTANCE (__first, __last, size_type);
      _C_init(__n);
      _C_copy(__first, __last, _C_start);
    }
    vector (const bool* __first, const bool* __last)
      : _C_end_of_storage(0)
    {
      size_type __n = _DISTANCE (__first, __last, size_type);
      _C_init(__n);
      _C_copy(__first, __last, _C_start);
    }
#endif
  
    ~vector () {
      _C_value_alloc_type(*this).deallocate(_C_start._C_p,  
        _C_end_of_storage - _C_start._C_p); 
    }
    _C_self& operator= (const _C_self& __x)
    {
      if (&__x == this) return *this;
      if (__x.size() > capacity())
      {
        _C_value_alloc_type(*this).deallocate(_C_start._C_p,
          _C_end_of_storage - _C_start._C_p); 
        _C_init(__x.size());
      }
      _C_copy(__x.begin(), __x.end(), begin());
      _C_finish = begin() + __x.size();

⌨️ 快捷键说明

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