Skip to content

Commit de03266

Browse files
committed
EnumArray: Fix iterator not being copyable
1 parent b7ebce3 commit de03266

2 files changed

Lines changed: 15 additions & 15 deletions

File tree

include/NazaraUtils/EnumArray.hpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,15 +39,15 @@ namespace Nz
3939
constexpr kv_iterator begin() noexcept;
4040
constexpr kv_iterator end() noexcept;
4141

42-
EnumArray& arrayRef;
42+
EnumArray* arrayRef;
4343
};
4444

4545
struct kv_const_iter_tag
4646
{
4747
constexpr kv_const_iterator begin() const noexcept;
4848
constexpr kv_const_iterator end() const noexcept;
4949

50-
const EnumArray& arrayRef;
50+
const EnumArray* arrayRef;
5151
};
5252
};
5353

@@ -93,7 +93,7 @@ namespace Nz
9393
constexpr bool operator>=(const EnumArrayKvIterator& rhs) const noexcept;
9494

9595
private:
96-
std::conditional_t<Const, const Array, Array>& m_array;
96+
std::conditional_t<Const, const Array, Array>* m_array;
9797
difference_type m_index;
9898
};
9999

include/NazaraUtils/EnumArray.inl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@ namespace Nz
99
template<typename E, typename V>
1010
constexpr auto EnumArray<E, V>::iter_kv() noexcept -> kv_iter_tag
1111
{
12-
return kv_iter_tag{ *this };
12+
return kv_iter_tag{ this };
1313
}
1414

1515
template<typename E, typename V>
1616
constexpr auto EnumArray<E, V>::iter_kv() const noexcept -> kv_const_iter_tag
1717
{
18-
return kv_const_iter_tag{ *this };
18+
return kv_const_iter_tag{ this };
1919
}
2020

2121
template<typename E, typename V>
@@ -40,7 +40,7 @@ namespace Nz
4040
template<typename E, typename V>
4141
constexpr typename EnumArray<E, V>::kv_iterator EnumArray<E, V>::kv_iter_tag::end() noexcept
4242
{
43-
return EnumArray<E, V>::kv_iterator(*this, arrayRef.size());
43+
return EnumArray<E, V>::kv_iterator(*this, arrayRef->size());
4444
}
4545

4646
template<typename E, typename V>
@@ -52,7 +52,7 @@ namespace Nz
5252
template<typename E, typename V>
5353
constexpr typename EnumArray<E, V>::kv_const_iterator EnumArray<E, V>::kv_const_iter_tag::end() const noexcept
5454
{
55-
return EnumArray<E, V>::kv_const_iterator(*this, arrayRef.size());
55+
return EnumArray<E, V>::kv_const_iterator(*this, arrayRef->size());
5656
}
5757

5858

@@ -125,55 +125,55 @@ namespace Nz
125125
constexpr auto EnumArrayKvIterator<E, V, Const>::operator*() const noexcept -> value_type
126126
{
127127
E enumKey = static_cast<E>(m_index);
128-
return std::make_pair(enumKey, std::ref(m_array[enumKey]));
128+
return std::make_pair(enumKey, std::ref((*m_array)[enumKey]));
129129
}
130130

131131
template<typename E, typename V, bool Const>
132132
constexpr auto EnumArrayKvIterator<E, V, Const>::operator[](difference_type n) const noexcept -> value_type
133133
{
134134
E enumKey = static_cast<E>(m_index + n);
135-
return std::make_pair(enumKey, std::ref(m_array[enumKey]));
135+
return std::make_pair(enumKey, std::ref((*m_array)[enumKey]));
136136
}
137137

138138
template<typename E, typename V, bool Const>
139139
constexpr bool EnumArrayKvIterator<E, V, Const>::operator==(const EnumArrayKvIterator& rhs) const noexcept
140140
{
141-
assert(&m_array == &rhs.m_array);
141+
assert(m_array == rhs.m_array);
142142
return m_index == rhs.m_index;
143143
}
144144

145145
template<typename E, typename V, bool Const>
146146
constexpr bool EnumArrayKvIterator<E, V, Const>::operator!=(const EnumArrayKvIterator& rhs) const noexcept
147147
{
148-
assert(&m_array == &rhs.m_array);
148+
assert(m_array == rhs.m_array);
149149
return m_index != rhs.m_index;
150150
}
151151

152152
template<typename E, typename V, bool Const>
153153
constexpr bool EnumArrayKvIterator<E, V, Const>::operator<(const EnumArrayKvIterator& rhs) const noexcept
154154
{
155-
assert(&m_array == &rhs.m_array);
155+
assert(m_array == rhs.m_array);
156156
return m_index < rhs.m_index;
157157
}
158158

159159
template<typename E, typename V, bool Const>
160160
constexpr bool EnumArrayKvIterator<E, V, Const>::operator<=(const EnumArrayKvIterator& rhs) const noexcept
161161
{
162-
assert(&m_array == &rhs.m_array);
162+
assert(m_array == rhs.m_array);
163163
return m_index <= rhs.m_index;
164164
}
165165

166166
template<typename E, typename V, bool Const>
167167
constexpr bool EnumArrayKvIterator<E, V, Const>::operator>(const EnumArrayKvIterator& rhs) const noexcept
168168
{
169-
assert(&m_array == &rhs.m_array);
169+
assert(m_array == rhs.m_array);
170170
return m_index > rhs.m_index;
171171
}
172172

173173
template<typename E, typename V, bool Const>
174174
constexpr bool EnumArrayKvIterator<E, V, Const>::operator>=(const EnumArrayKvIterator& rhs) const noexcept
175175
{
176-
assert(&m_array == &rhs.m_array);
176+
assert(m_array == rhs.m_array);
177177
return m_index >= rhs.m_index;
178178
}
179179

0 commit comments

Comments
 (0)