stl_deque.h

来自「symbian上STL模板库的实现」· C头文件 代码 · 共 1,143 行 · 第 1/5 页

H
1,143
字号
                                     *  out_of_range if the check fails.                                     */                                    reference                                        at(size_type __n)                                        { _M_range_check(__n); return (*this)[__n]; }                                    /**                                     *  @brief  Provides access to the data contained in the %deque.                                     *  @param  n  The index of the element for which data should be accessed.                                     *  @return  Read-only (constant) reference to data.                                     *  @throw  std::out_of_range  If @a n is an invalid index.                                     *                                     *  This function provides for safer data access.  The parameter is first                                     *  checked that it is in the range of the deque.  The function throws                                     *  out_of_range if the check fails.                                     */                                    const_reference                                        at(size_type __n) const                                        {                                            _M_range_check(__n);                                            return (*this)[__n];                                        }                                    /**                                     *  Returns a read/write reference to the data at the first element of the                                     *  %deque.                                     */                                    reference                                        front()                                        { return *this->_M_impl._M_start; }                                    /**                                     *  Returns a read-only (constant) reference to the data at the first                                     *  element of the %deque.                                     */                                    const_reference                                        front() const                                        { return *this->_M_impl._M_start; }                                    /**                                     *  Returns a read/write reference to the data at the last element of the                                     *  %deque.                                     */                                    reference                                        back()                                        {                                            iterator __tmp = this->_M_impl._M_finish;                                            --__tmp;                                            return *__tmp;                                        }                                    /**                                     *  Returns a read-only (constant) reference to the data at the last                                     *  element of the %deque.                                     */                                    const_reference                                        back() const                                        {                                            const_iterator __tmp = this->_M_impl._M_finish;                                            --__tmp;                                            return *__tmp;                                        }                                    // [23.2.1.2] modifiers                                    /**                                     *  @brief  Add data to the front of the %deque.                                     *  @param  x  Data to be added.                                     *                                     *  This is a typical stack operation.  The function creates an element at                                     *  the front of the %deque and assigns the given data to it.  Due to the                                     *  nature of a %deque this operation can be done in constant time.                                     */                                    void                                        push_front(const value_type& __x)                                        {                                            if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_first)                                            {                                                std::_Construct(this->_M_impl._M_start._M_cur - 1, __x);                                                --this->_M_impl._M_start._M_cur;                                            }                                            else                                                _M_push_front_aux(__x);                                        }                                    /**                                     *  @brief  Add data to the end of the %deque.                                     *  @param  x  Data to be added.                                     *                                     *  This is a typical stack operation.  The function creates an element at                                     *  the end of the %deque and assigns the given data to it.  Due to the                                     *  nature of a %deque this operation can be done in constant time.                                     */                                    void                                        push_back(const value_type& __x)                                        {                                            if (this->_M_impl._M_finish._M_cur != this->_M_impl._M_finish._M_last - 1)                                            {                                                std::_Construct(this->_M_impl._M_finish._M_cur, __x);                                                ++this->_M_impl._M_finish._M_cur;                                            }                                            else                                                _M_push_back_aux(__x);                                        }                                    /**                                     *  @brief  Removes first element.                                     *                                     *  This is a typical stack operation.  It shrinks the %deque by one.                                     *                                     *  Note that no data is returned, and if the first element's data is                                     *  needed, it should be retrieved before pop_front() is called.                                     */                                    void                                        pop_front()                                        {                                            if (this->_M_impl._M_start._M_cur != this->_M_impl._M_start._M_last - 1)                                            {                                                std::_Destroy(this->_M_impl._M_start._M_cur);                                                ++this->_M_impl._M_start._M_cur;                                            }                                            else                                                _M_pop_front_aux();                                        }                                    /**                                     *  @brief  Removes last element.                                     *                                     *  This is a typical stack operation.  It shrinks the %deque by one.                                     *                                     *  Note that no data is returned, and if the last element's data is                                     *  needed, it should be retrieved before pop_back() is called.                                     */                                    void                                        pop_back()                                        {                                            if (this->_M_impl._M_finish._M_cur != this->_M_impl._M_finish._M_first)                                            {                                                --this->_M_impl._M_finish._M_cur;                                                std::_Destroy(this->_M_impl._M_finish._M_cur);                                            }                                            else                                                _M_pop_back_aux();                                        }                                    /**                                     *  @brief  Inserts given value into %deque before specified iterator.                                     *  @param  position  An iterator into the %deque.                                     *  @param  x  Data to be inserted.                                     *  @return  An iterator that points to the inserted data.                                     *                                     *  This function will insert a copy of the given value before the                                     *  specified location.                                     */                                    iterator                                        insert(iterator position, const value_type& __x);                                    /**                                     *  @brief  Inserts a number of copies of given data into the %deque.                                     *  @param  position  An iterator into the %deque.                                     *  @param  n  Number of elements to be inserted.                                     *  @param  x  Data to be inserted.                                     *                                     *  This function will insert a specified number of copies of the given                                     *  data before the location specified by @a position.                                     */                                    void                                        insert(iterator __position, size_type __n, const value_type& __x)                                        { _M_fill_insert(__position, __n, __x); }                                    /**                                     *  @brief  Inserts a range into the %deque.                                     *  @param  position  An iterator into the %deque.                                     *  @param  first  An input iterator.                                     *  @param  last   An input iterator.                                     *                                     *  This function will insert copies of the data in the range [first,last)                                     *  into the %deque before the location specified by @a pos.  This is                                     *  known as "range insert."                                     */                                    template<typename _InputIterator>                                        void                                        insert(iterator __position, _InputIterator __first,                                                _InputIterator __last)                                        {                                            // Check whether it's an integral type.  If so, it's not an iterator.                                            typedef typename _Is_integer<_InputIterator>::_Integral _Integral;                                            _M_insert_dispatch(__position, __first, __last, _Integral());                                        }                                    /**                                     *  @brief  Remove element at given position.                                     *  @param  position  Iterator pointing to element to be erased.                                     *  @return  An iterator pointing to the next element (or end()).                                     *                                     *  This function will erase the element at the given position and thus                                     *  shorten the %deque by one.                                     *                                     *  The user is cautioned that                                     *  this function only erases the element, and that if the element is                                     *  itself a pointer, the pointed-to memory is not touched in any way.                                     *  Managing the pointer is the user's responsibilty.                                     */                                    iterator                                        erase(iterator __position);                                    /**                                     *  @brief  Remove a range of elements.                                     *  @param  first  Iterator pointing to the first element to be erased.                                     *  @param  last  Iterator pointing to one past the last element to be                                     *                erased.                                     *  @return  An iterator pointing to the element pointed to by @a last                                     *           prior to erasing (or end()).                                     *                                     *  This function will erase the elements in the range [first,last) and                                     *  shorten the %deque accordingly.                                     *                                     *  The user is cautioned that                                     *  this function only erases the elements, and that if the elements                                     *  themselves are pointers, the pointed-to memory is not touched in any                                     *  way.  Managing the pointer is the user's responsibilty.                                     */                                    iterator                                        erase(iterator __first, iterator __last);                                    /**                                     *  @brief  Swaps data with another %deque.                    

⌨️ 快捷键说明

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