rework assignment/copy operator, add operator[] to DeallocatingVector RA-iterator
This commit is contained in:
parent
d5a9f8e177
commit
0592897859
@ -50,14 +50,10 @@ template <typename ElementT> struct DeallocatingVectorIteratorState
|
||||
std::size_t index;
|
||||
std::vector<ElementT *> *bucket_list;
|
||||
|
||||
inline DeallocatingVectorIteratorState &operator=(const DeallocatingVectorIteratorState &a)
|
||||
inline DeallocatingVectorIteratorState &operator=(const DeallocatingVectorIteratorState &other)
|
||||
{
|
||||
if (this != &a)
|
||||
{
|
||||
this->DeallocatingVectorIteratorState::
|
||||
~DeallocatingVectorIteratorState(); // explicit non-virtual destructor call
|
||||
new (this) DeallocatingVectorIteratorState(a); // placement new
|
||||
}
|
||||
index = other.index;
|
||||
bucket_list = other.bucket_list;
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
@ -102,6 +98,13 @@ class DeallocatingVectorIterator
|
||||
const std::size_t current_index = current_state.index % ELEMENTS_PER_BLOCK;
|
||||
return (current_state.bucket_list->at(current_bucket)[current_index]);
|
||||
}
|
||||
|
||||
ElementT &operator[](const std::size_t index) const
|
||||
{
|
||||
const std::size_t current_bucket = (index + current_state.index) / ELEMENTS_PER_BLOCK;
|
||||
const std::size_t current_index = (index + current_state.index) % ELEMENTS_PER_BLOCK;
|
||||
return (current_state.bucket_list->at(current_bucket)[current_index]);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK>
|
||||
|
Loading…
Reference in New Issue
Block a user