13 #ifndef STXXL_COMMON_SWAP_VECTOR_HEADER
14 #define STXXL_COMMON_SWAP_VECTOR_HEADER
33 template <
typename ValueType>
61 : m_size(0), m_capacity(0), m_array(NULL)
65 : m_size(size), m_capacity(size), m_array(NULL)
73 : m_size(size), m_capacity(std::
max(size, capacity)), m_array(NULL)
134 return m_array + m_size;
139 return m_array + m_size;
150 return *(begin() + i);
156 return *(begin() + i);
174 return *(m_array + m_size - 1);
180 return *(m_array + m_size - 1);
185 if (newsize > m_capacity)
191 for (
unsigned i = 0; i < m_size; ++i)
194 swap(tmp[i], m_array[i]);
202 m_capacity = newsize;
215 if (m_size + 1 > m_capacity)
220 swap(m_array[m_size], val);
232 return erase(position, position + 1);
238 assert(first >= begin());
239 assert(last <= end());
240 if (last < m_array + m_size - 1)
253 m_size -= (last - first);
266 template <
class ForwardIterator,
class UnaryPredicate>
267 ForwardIterator
swap_remove_if(ForwardIterator first, ForwardIterator last, UnaryPredicate pred)
269 ForwardIterator result = first;
270 while (first != last)
275 swap(*first, *result);
289 template <
class ValueType>
298 #endif // !STXXL_COMMON_SWAP_VECTOR_HEADER
void swap(swap_vector &obj)
Swap the vector with another one.
swap_vector()
Create an empty vector.
const value_type & const_reference
size_type m_capacity
size of allocated memory
iterator erase(iterator position)
Erase the element at the given position by swapping it to the and and then reducing the vector size...
ForwardIterator swap_remove_if(ForwardIterator first, ForwardIterator last, UnaryPredicate pred)
Transforms the range [first,last) into a range with all the elements for which pred returns true remo...
swap_vector(size_type size)
Create a vector with the spezified size.
const_iterator end() const
Return constant iterator beyond the last element.
void swap_back(reference val)
Create a new value_type object at the end of the vector and then swap it with val.
reference front()
Return reference to first element.
value_type * m_array
pointer to allocated memory area
const_iterator cend() const
Return constant iterator beyond the last element.
const_iterator begin() const
Return constant iterator to the first element.
const value_type * const_iterator
void reserve(size_type newsize)
Resize the underlaying array to contain at least newsize items.
size_type capacity() const
Return the size of the underlaying array.
size_type size() const
Return the vector size.
void clear()
Clear the vector. The capacity doesn't change.
iterator data()
Return iterator to the beginning of vector.
size_type m_size
size of vector
bool empty() const
Return the vector size.
~swap_vector()
Delete the vector.
iterator end()
Return mutable iterator beyond the last element.
#define STXXL_BEGIN_NAMESPACE
static uint_pair max()
return an uint_pair instance containing the largest value possible
const_reference back() const
Return reference to last element.
const_iterator cbegin() const
Return constant iterator to the first element.
const_reference front() const
Return constant reference to first element.
swap_vector(size_type size, size_type capacity)
Create a vector with the spezified size and reserve (possibly more) space.
iterator begin()
Return mutable iterator to the first element.
Vector that avoids copying of ValueType objects in push_back() (here: swap_back()) and resize() opera...
iterator erase(iterator first, iterator last)
Erase the elements at in the range [begin,last) by swapping them to the and and then reducing the vec...
const_iterator data() const
Return iterator to the beginning of vector.
void resize(size_type newsize)
Resize the vector to contain at least newsize items.
reference back()
Return reference to last element.
#define STXXL_END_NAMESPACE