sparse_set: added const_iterator/const_reverse_iterator and cbegin/cend/crbegin/crend
This commit is contained in:
@@ -284,8 +284,12 @@ public:
|
||||
using pointer = typename packed_container_type::const_pointer;
|
||||
/*! @brief Random access iterator type. */
|
||||
using iterator = internal::sparse_set_iterator<packed_container_type>;
|
||||
/*! @brief Constant random access iterator type. */
|
||||
using const_iterator = iterator;
|
||||
/*! @brief Reverse iterator type. */
|
||||
using reverse_iterator = std::reverse_iterator<iterator>;
|
||||
/*! @brief Constant reverse iterator type. */
|
||||
using const_reverse_iterator = reverse_iterator;
|
||||
|
||||
/*! @brief Default constructor. */
|
||||
basic_sparse_set()
|
||||
@@ -482,11 +486,16 @@ public:
|
||||
*
|
||||
* @return An iterator to the first entity of the sparse set.
|
||||
*/
|
||||
[[nodiscard]] iterator begin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_iterator begin() const ENTT_NOEXCEPT {
|
||||
const auto pos = static_cast<typename iterator::difference_type>(packed.size());
|
||||
return iterator{&packed, pos};
|
||||
}
|
||||
|
||||
/*! @brief begin */
|
||||
[[nodiscard]] const_iterator cbegin() const ENTT_NOEXCEPT {
|
||||
return begin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns an iterator to the end.
|
||||
*
|
||||
@@ -501,6 +510,11 @@ public:
|
||||
return iterator{&packed, {}};
|
||||
}
|
||||
|
||||
/*! @brief end */
|
||||
[[nodiscard]] const_iterator cend() const ENTT_NOEXCEPT {
|
||||
return end();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a reverse iterator to the beginning.
|
||||
*
|
||||
@@ -511,10 +525,15 @@ public:
|
||||
* @return An iterator to the first entity of the reversed internal packed
|
||||
* array.
|
||||
*/
|
||||
[[nodiscard]] reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
||||
[[nodiscard]] const_reverse_iterator rbegin() const ENTT_NOEXCEPT {
|
||||
return std::make_reverse_iterator(end());
|
||||
}
|
||||
|
||||
/*! @brief rbegin */
|
||||
[[nodiscard]] const_reverse_iterator crbegin() const ENTT_NOEXCEPT {
|
||||
return rbegin();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Returns a reverse iterator to the end.
|
||||
*
|
||||
@@ -529,6 +548,11 @@ public:
|
||||
return std::make_reverse_iterator(begin());
|
||||
}
|
||||
|
||||
/*! @brief rend */
|
||||
[[nodiscard]] const_reverse_iterator crend() const ENTT_NOEXCEPT {
|
||||
return rend();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Finds an entity.
|
||||
* @param entt A valid identifier.
|
||||
|
||||
@@ -804,8 +804,8 @@ TEST(SparseSet, Iterator) {
|
||||
begin = set.end();
|
||||
std::swap(begin, end);
|
||||
|
||||
ASSERT_EQ(begin, set.begin());
|
||||
ASSERT_EQ(end, set.end());
|
||||
ASSERT_EQ(begin, set.cbegin());
|
||||
ASSERT_EQ(end, set.cend());
|
||||
ASSERT_NE(begin, end);
|
||||
|
||||
ASSERT_EQ(begin++, set.begin());
|
||||
@@ -859,8 +859,8 @@ TEST(SparseSet, ReverseIterator) {
|
||||
begin = set.rend();
|
||||
std::swap(begin, end);
|
||||
|
||||
ASSERT_EQ(begin, set.rbegin());
|
||||
ASSERT_EQ(end, set.rend());
|
||||
ASSERT_EQ(begin, set.crbegin());
|
||||
ASSERT_EQ(end, set.crend());
|
||||
ASSERT_NE(begin, end);
|
||||
|
||||
ASSERT_EQ(begin++, set.rbegin());
|
||||
|
||||
Reference in New Issue
Block a user