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::size_t index;
|
||||||
std::vector<ElementT *> *bucket_list;
|
std::vector<ElementT *> *bucket_list;
|
||||||
|
|
||||||
inline DeallocatingVectorIteratorState &operator=(const DeallocatingVectorIteratorState &a)
|
inline DeallocatingVectorIteratorState &operator=(const DeallocatingVectorIteratorState &other)
|
||||||
{
|
{
|
||||||
if (this != &a)
|
index = other.index;
|
||||||
{
|
bucket_list = other.bucket_list;
|
||||||
this->DeallocatingVectorIteratorState::
|
|
||||||
~DeallocatingVectorIteratorState(); // explicit non-virtual destructor call
|
|
||||||
new (this) DeallocatingVectorIteratorState(a); // placement new
|
|
||||||
}
|
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -102,6 +98,13 @@ class DeallocatingVectorIterator
|
|||||||
const std::size_t current_index = current_state.index % ELEMENTS_PER_BLOCK;
|
const std::size_t current_index = current_state.index % ELEMENTS_PER_BLOCK;
|
||||||
return (current_state.bucket_list->at(current_bucket)[current_index]);
|
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>
|
template <typename ElementT, std::size_t ELEMENTS_PER_BLOCK>
|
||||||
|
Loading…
Reference in New Issue
Block a user