stl_deque.h
来自「symbian上STL模板库的实现」· C头文件 代码 · 共 1,143 行 · 第 1/5 页
H
1,143 行
deque(_InputIterator __first, _InputIterator __last, const allocator_type& __a = allocator_type()) : _Base(__a) { // Check whether it's an integral type. If so, it's not an iterator. typedef typename _Is_integer<_InputIterator>::_Integral _Integral; _M_initialize_dispatch(__first, __last, _Integral()); } /** * The dtor only erases the elements, and note 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. */ ~deque() { std::_Destroy(this->_M_impl._M_start, this->_M_impl._M_finish); } /** * @brief %Deque assignment operator. * @param x A %deque of identical element and allocator types. * * All the elements of @a x are copied, but unlike the copy constructor, * the allocator object is not copied. */ deque& operator=(const deque& __x); /** * @brief Assigns a given value to a %deque. * @param n Number of elements to be assigned. * @param val Value to be assigned. * * This function fills a %deque with @a n copies of the given value. * Note that the assignment completely changes the %deque and that the * resulting %deque's size is the same as the number of elements assigned. * Old data may be lost. */ void assign(size_type __n, const value_type& __val) { _M_fill_assign(__n, __val); } /** * @brief Assigns a range to a %deque. * @param first An input iterator. * @param last An input iterator. * * This function fills a %deque with copies of the elements in the * range [first,last). * * Note that the assignment completely changes the %deque and that the * resulting %deque's size is the same as the number of elements * assigned. Old data may be lost. */ template<typename _InputIterator> void assign(_InputIterator __first, _InputIterator __last) { typedef typename _Is_integer<_InputIterator>::_Integral _Integral; _M_assign_dispatch(__first, __last, _Integral()); } /// Get a copy of the memory allocation object. allocator_type get_allocator() const { return _Base::get_allocator(); } // iterators /** * Returns a read/write iterator that points to the first element in the * %deque. Iteration is done in ordinary element order. */ iterator begin() { return this->_M_impl._M_start; } /** * Returns a read-only (constant) iterator that points to the first * element in the %deque. Iteration is done in ordinary element order. */ const_iterator begin() const { return this->_M_impl._M_start; } /** * Returns a read/write iterator that points one past the last element in * the %deque. Iteration is done in ordinary element order. */ iterator end() { return this->_M_impl._M_finish; } /** * Returns a read-only (constant) iterator that points one past the last * element in the %deque. Iteration is done in ordinary element order. */ const_iterator end() const { return this->_M_impl._M_finish; } /** * Returns a read/write reverse iterator that points to the last element * in the %deque. Iteration is done in reverse element order. */ reverse_iterator rbegin() { return reverse_iterator(this->_M_impl._M_finish); } /** * Returns a read-only (constant) reverse iterator that points to the * last element in the %deque. Iteration is done in reverse element * order. */ const_reverse_iterator rbegin() const { return const_reverse_iterator(this->_M_impl._M_finish); } /** * Returns a read/write reverse iterator that points to one before the * first element in the %deque. Iteration is done in reverse element * order. */ reverse_iterator rend() { return reverse_iterator(this->_M_impl._M_start); } /** * Returns a read-only (constant) reverse iterator that points to one * before the first element in the %deque. Iteration is done in reverse * element order. */ const_reverse_iterator rend() const { return const_reverse_iterator(this->_M_impl._M_start); } // [23.2.1.2] capacity /** Returns the number of elements in the %deque. */ size_type size() const { return this->_M_impl._M_finish - this->_M_impl._M_start; } /** Returns the size() of the largest possible %deque. */ size_type max_size() const { return size_type(-1); } /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. * @param x Data with which new elements should be populated. * * This function will %resize the %deque to the specified number of * elements. If the number is smaller than the %deque's current size the * %deque is truncated, otherwise the %deque is extended and new elements * are populated with given data. */ void resize(size_type __new_size, const value_type& __x) { const size_type __len = size(); if (__new_size < __len) erase(this->_M_impl._M_start + __new_size, this->_M_impl._M_finish); else insert(this->_M_impl._M_finish, __new_size - __len, __x); } /** * @brief Resizes the %deque to the specified number of elements. * @param new_size Number of elements the %deque should contain. * * This function will resize the %deque to the specified number of * elements. If the number is smaller than the %deque's current size the * %deque is truncated, otherwise the %deque is extended and new elements * are default-constructed. */ void resize(size_type new_size) { resize(new_size, value_type()); } /** * Returns true if the %deque is empty. (Thus begin() would equal end().) */ bool empty() const { return this->_M_impl._M_finish == this->_M_impl._M_start; } // element access /** * @brief Subscript access to the data contained in the %deque. * @param n The index of the element for which data should be accessed. * @return Read/write reference to data. * * This operator allows for easy, array-style, data access. * Note that data access with this operator is unchecked and out_of_range * lookups are not defined. (For checked lookups see at().) */ reference operator[](size_type __n) { return this->_M_impl._M_start[difference_type(__n)]; } /** * @brief Subscript 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. * * This operator allows for easy, array-style, data access. * Note that data access with this operator is unchecked and out_of_range * lookups are not defined. (For checked lookups see at().) */ const_reference operator[](size_type __n) const { return this->_M_impl._M_start[difference_type(__n)]; } protected: /// @if maint Safety check used only from at(). @endif void _M_range_check(size_type __n) const { if (__n >= this->size()) __throw_out_of_range(__N("deque::_M_range_check")); } public: /** * @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/write 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
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?