This is an internal header file, included by other library headers. More...
#include <bits/concept_check.h>
#include <bits/stl_iterator_base_types.h>
#include <bits/stl_iterator_base_funcs.h>
Macros | |
#define | _GLIBCXX_DEQUE_BUF_SIZE 512 |
Functions | |
namespace std | _GLIBCXX_VISIBILITY (default) |
This is an internal header file, included by other library headers.
Do not attempt to use it directly. {deque}
#define _GLIBCXX_DEQUE_BUF_SIZE 512 |
Referenced by _GLIBCXX_VISIBILITY().
namespace std _GLIBCXX_VISIBILITY | ( | default | ) |
This function controls the size of memory nodes.
__size | The size of an element. |
This function started off as a compiler kludge from SGI, but seems to be a useful wrapper around a repeated constant expression. The 512 is tunable (and no other code needs to change), but no investigation has been done since inheriting the SGI code. Touch _GLIBCXX_DEQUE_BUF_SIZE only if you know what you are doing, however: changing it breaks the binary compatibility!!
A deque::iterator.
Quite a bit of intelligence here. Much of the functionality of deque is actually passed off to this class. A deque holds two of these internally, marking its valid range. Access to elements is done as offsets of either of those two, relying on operator overloading in this class.
All the functions are op overloads except for _M_set_node.
Prepares to traverse new_node. Sets everything except _M_cur, which should therefore be set by the caller immediately afterwards, based on _M_first and _M_last.
Deque base class. This class provides the unified face for deque's allocation. This class's constructor and destructor allocate and deallocate (but do not initialize) storage. This makes exception safety easier.
Nothing in this class ever constructs or destroys an actual Tp element. (Deque handles that itself.) Only/All memory management is performed here.
Layout storage.
__num_elements | The count of T's for which to allocate space at first. |
The initial underlying memory layout is a bit complicated...
A standard container using fixed-size memory allocation and constant-time manipulation of elements at either end.
_Tp | Type of element. |
_Alloc | Allocator type, defaults to allocator<_Tp>. |
Meets the requirements of a container, a reversible container, and a sequence, including the optional sequence requirements.
In previous HP/SGI versions of deque, there was an extra template parameter so users could control the node size. This extension turned out to violate the C++ standard (it can be detected using template template parameters), and it was removed.
Here's how a deque<Tp> manages memory. Each deque has 4 members:
map_size is at least 8. map is an array of map_size pointers-to-nodes. (The name map has nothing to do with the std::map class, and nodes should not be confused with std::list's usage of node.)
A node has no specific type name as such, but it is referred to as node in this file. It is a simple array-of-Tp. If Tp is very large, there will be one Tp element per node (i.e., an array of one). For non-huge Tp's, node size is inversely related to Tp size: the larger the Tp, the fewer Tp's will fit in a node. The goal here is to keep the total size of a node relatively small and constant over different Tp's, to improve allocator efficiency.
Not every pointer in the map array will point to a node. If the initial number of elements in the deque is small, the /middle/ map pointers will be valid, and the ones at the edges will be unused. This same situation will arise as the map grows: available map pointers, if any, will be on the ends. As new nodes are created, only a subset of the map's pointers need to be copied outward.
Class invariants:
A pointer in the range [map, map + map_size) points to an allocated node if and only if the pointer is in the range [start.node, finish.node].
Here's the magic: nothing in deque is aware of the discontiguous storage!
The memory setup and layout occurs in the parent, _Base, and the iterator class is entirely responsible for leaping from one node to the next. All the implementation routines for deque itself work only through the start and finish iterators. This keeps the routines simple and sane, and we can use other standard algorithms as well.
A total of four data members accumulated down the hierarchy. May be accessed via _M_impl.*
Creates a deque with no elements.
Creates a deque with no elements.
__a | An allocator object. |
Creates a deque with copies of an exemplar element.
__n | The number of elements to initially create. |
__value | An element to copy. |
__a | An allocator. |
This constructor fills the deque with __n copies of __value.
Deque copy constructor.
__x | A deque of identical element and allocator types. |
The newly-created deque uses a copy of the allocation object used by __x.
Builds a deque from a range.
__first | An input iterator. |
__last | An input iterator. |
__a | An allocator object. |
Create a deque consisting of copies of the elements from [__first, __last).
If the iterators are forward, bidirectional, or random-access, then this will call the elements' copy constructor N times (where N is distance(__first,__last)) and do no memory reallocation. But if only input iterators are used, then this will do at most 2N calls to the copy constructor, and logN memory reallocations.
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 responsibility.
Deque assignment operator.
__x | A deque of identical element and allocator types. |
All the elements of x are copied, but unlike the copy constructor, the allocator object is not copied.
Assigns a given value to a deque.
__n | Number of elements to be assigned. |
__val | Value to be assigned. |
This function fills a deque with 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.
Assigns a range to a deque.
__first | An input iterator. |
__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.
Get a copy of the memory allocation object.
Returns a read/write iterator that points to the first element in the deque. Iteration is done in ordinary element order.
Returns a read-only (constant) iterator that points to the first element in the deque. Iteration is done in ordinary element order.
Returns a read/write iterator that points one past the last element in the deque. Iteration is done in ordinary element order.
Returns a read-only (constant) iterator that points one past the last element in the deque. Iteration is done in ordinary element order.
Returns a read/write reverse iterator that points to the last element in the deque. Iteration is done in reverse element order.
Returns a read-only (constant) reverse iterator that points to the last element in the deque. Iteration is done in reverse element order.
Returns a read/write reverse iterator that points to one before the first element in the deque. Iteration is done in reverse element order.
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.
Returns the number of elements in the deque.
Returns the size() of the largest possible deque.
Resizes the deque to the specified number of elements.
__new_size | Number of elements the deque should contain. |
__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.
Returns true if the deque is empty. (Thus begin() would equal end().)
Subscript access to the data contained in the deque.
__n | The index of the element for which data should be accessed. |
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().)
Subscript access to the data contained in the deque.
__n | The index of the element for which data should be accessed. |
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().)
Safety check used only from at().
Provides access to the data contained in the deque.
__n | The index of the element for which data should be accessed. |
std::out_of_range | If __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.
Provides access to the data contained in the deque.
__n | The index of the element for which data should be accessed. |
std::out_of_range | If __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.
Returns a read/write reference to the data at the first element of the deque.
Returns a read-only (constant) reference to the data at the first element of the deque.
Returns a read/write reference to the data at the last element of the deque.
Returns a read-only (constant) reference to the data at the last element of the deque.
Add data to the front of the deque.
__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.
Add data to the end of the deque.
__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.
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.
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.
Inserts given value into deque before specified iterator.
__position | An iterator into the deque. |
__x | Data to be inserted. |
This function will insert a copy of the given value before the specified location.
Inserts a number of copies of given data into the deque.
__position | An iterator into the deque. |
__n | Number of elements to be inserted. |
__x | Data to be inserted. |
This function will insert a specified number of copies of the given data before the location specified by __position.
Inserts a range into the deque.
__position | An iterator into the deque. |
__first | An input iterator. |
__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 __position. This is known as range insert.
Remove element at given position.
__position | Iterator pointing to element to be erased. |
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 responsibility.
Remove a range of elements.
__first | Iterator pointing to the first element to be erased. |
__last | Iterator pointing to one past the last element to be erased. |
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 responsibility.
Swaps data with another deque.
__x | A deque of the same element and allocator types. |
This exchanges the elements between two deques in constant time. (Four pointers, so it should be quite fast.) Note that the global std::swap() function is specialized such that std::swap(d1,d2) will feed to this function.
Erases all the elements. Note 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 responsibility.
Fills the deque with whatever is in [first,last).
__first | An input iterator. |
__last | An input iterator. |
If the iterators are actually forward iterators (or better), then the memory layout can be done all at once. Else we move forward using push_back on each value from the iterator.
Fills the deque with copies of value.
__value | Initial value. |
This function is called only when the user provides an explicit size (with or without an explicit exemplar value).
Helper functions for push_* and pop_*.
Memory-handling helpers for the previous internal insert functions.
Memory-handling helpers for the major map.
Makes sure the _M_map has space for new nodes. Does not actually add the nodes. Can invalidate _M_map pointers. (And consequently, deque iterators.)
Deque equality comparison.
__x | A deque. |
__y | A deque of the same type as __x. |
This is an equivalence relation. It is linear in the size of the deques. Deques are considered equivalent if their sizes are equal, and if corresponding elements compare equal.
Deque ordering relation.
__x | A deque. |
__y | A deque of the same type as __x. |
This is a total ordering relation. It is linear in the size of the deques. The elements must be comparable with <
.
See std::lexicographical_compare() for how the determination is made.
Based on operator==
Based on operator<
Based on operator<
Based on operator<
See std::deque::swap().
References __catch, __glibcxx_class_requires, __glibcxx_class_requires2, __gnu_profile::__size(), __throw_exception_again, __try, _GLIBCXX_DEQUE_BUF_SIZE, __gnu_parallel::max(), std::__exception_ptr::operator!=(), __gnu_debug::operator+(), __gnu_debug::operator-(), std::__exception_ptr::operator==(), __gnu_debug::operator>(), __gnu_debug::operator>=(), and std::__exception_ptr::swap().