Function erase
Summary
#include <include/EASTL/bitvector.h>
(1) iterator erase(const_iterator position)
(2) iterator erase(const_iterator first, const_iterator last)
(3) reverse_iterator erase(const_reverse_iterator position)
(4) reverse_iterator erase(const_reverse_iterator first, const_reverse_iterator last)
Function overload
Synopsis
#include <include/EASTL/bitvector.h>
iterator erase(const_iterator position)
Description
template <typename InputIterator> Not yet implemented. See below for disabled definition. void insert(const_iterator position, InputIterator first, InputIterator last);
The following is a placeholder for a future implementation. It turns out that a correct implementation of
insert(pos, first, last) is a non-trivial exercise that would take a few hours to implement and test.
The reasons why involve primarily the problem of handling the case where insertion source comes from
within the container itself, and the case that first and last (note they are templated) might not refer
to iterators might refer to a value/count pair. The C++ Standard requires you to handle this case and
I (Paul Pedriana) believe that it applies even for a bitvector, given that bool is an integral type.
So you have to set up a compile-time type traits function chooser. See vector, for example.
template <typename Allocator, typename Element, typename Container>
template <typename InputIterator>
void bitvector<Allocator, Element, Container>::insert(const_iterator position, InputIterator first, InputIterator last)
{
iterator iPosition(position.get_reference_type()); // This is just a non-const version of position.
/ This implementation is probably broken due to not handling insertion into self. / To do: Make a more efficient version of this. difference_type distance = (iPosition - begin());
while(first != last) { insert(iPosition, *first); iPosition = begin() + ++distance; ++first; } }
Source
Lines 1238-1255 in include/EASTL/bitvector.h. Line 319 in include/EASTL/bitvector.h.
template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::iterator
bitvector<Allocator, Element, Container>::erase(const_iterator position)
{
iterator iPosition(position.get_reference_type()); // This is just a non-const version of position.
#if EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(validate_iterator(iPosition) & eastl::isf_can_dereference) == 0)
EASTL_FAIL_MSG("bitvector::erase -- invalid iterator");
#endif
MoveBits(++iterator(iPosition), end(), iPosition);
resize(size() - 1);
// Verify that no reallocation occurred.
EASTL_ASSERT(validate_iterator(iPosition) & eastl::isf_valid);
return iPosition;
}
Synopsis
#include <include/EASTL/bitvector.h>
iterator erase(const_iterator first, const_iterator last)
Description
No description yet.
Source
Lines 1258-1289 in include/EASTL/bitvector.h. Line 320 in include/EASTL/bitvector.h.
template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::iterator
bitvector<Allocator, Element, Container>::erase(const_iterator first, const_iterator last)
{
iterator iFirst(first.get_reference_type()); // This is just a non-const version of first.
iterator iLast(last.get_reference_type()); // This is just a non-const version of last.
#if EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(validate_iterator(iLast) & eastl::isf_valid) == 0)
EASTL_FAIL_MSG("bitvector::erase -- invalid iterator");
#endif
if(!(iFirst == iLast))
{
#if EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(validate_iterator(iFirst) & eastl::isf_can_dereference) == 0)
EASTL_FAIL_MSG("bitvector::erase -- invalid iterator");
#endif
const size_type eraseCount = (size_type)(iLast - iFirst);
MoveBits(iLast, end(), iFirst);
resize(size() - eraseCount);
// Verify that no reallocation occurred.
#if EASTL_ASSERT_ENABLED
if(EASTL_UNLIKELY(validate_iterator(iFirst) & eastl::isf_valid) == 0)
EASTL_FAIL_MSG("bitvector::erase -- invalid iterator");
#endif
}
return iFirst;
}
Synopsis
#include <include/EASTL/bitvector.h>
reverse_iterator erase(const_reverse_iterator position)
Description
No description yet.
Source
Lines 1292-1297 in include/EASTL/bitvector.h. Line 322 in include/EASTL/bitvector.h.
template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::reverse_iterator
bitvector<Allocator, Element, Container>::erase(const_reverse_iterator position)
{
return reverse_iterator(erase((++position).base()));
}
Synopsis
#include <include/EASTL/bitvector.h>
reverse_iterator erase(const_reverse_iterator first, const_reverse_iterator last)
Description
No description yet.
Source
Lines 1300-1312 in include/EASTL/bitvector.h. Line 323 in include/EASTL/bitvector.h.
template <typename Allocator, typename Element, typename Container>
typename bitvector<Allocator, Element, Container>::reverse_iterator
bitvector<Allocator, Element, Container>::erase(const_reverse_iterator first, const_reverse_iterator last)
{
// Version which erases in order from first to last.
// difference_type i(first.base() - last.base());
// while(i--)
// first = erase(first);
// return first;
// Version which erases in order from last to first, but is slightly more efficient:
return reverse_iterator(erase(last.base(), first.base()));
}