Skip to content

Commit 62c8435

Browse files
valid iterator check to Eigen Matrix graph iterator
1 parent a14940d commit 62c8435

2 files changed

Lines changed: 8 additions & 0 deletions

File tree

include/osp/graph_implementations/eigen_matrix_adapter/eigen_sparse_iterator.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ class EigenCSRRange {
7777
}
7878

7979
inline bool operator!=(const Iterator &other) const { return not(*this == other); }
80+
81+
inline operator bool() const { return it_; }
8082
};
8183

8284
EigenCSRRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}
@@ -140,6 +142,8 @@ class EigenCSCRange {
140142
}
141143

142144
inline bool operator!=(const Iterator &other) const { return not(*this == other); }
145+
146+
inline operator bool() const { return it_; }
143147
};
144148

145149
EigenCSCRange(const Graph &graph, EigenIdxType idx) : graph_(graph), index_(idx) {}

tests/sparse_matrix_impl.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,7 @@ BOOST_AUTO_TEST_CASE(TestSparseMatrixAdapter2) {
262262
BOOST_CHECK(it == it_other);
263263
BOOST_CHECK(cntr == 0U || it != begin);
264264
BOOST_CHECK(cntr == 0U || (not (it == begin)));
265+
BOOST_CHECK_EQUAL(it, it != end);
265266

266267
++cntr;
267268
++it;
@@ -273,6 +274,7 @@ BOOST_AUTO_TEST_CASE(TestSparseMatrixAdapter2) {
273274
BOOST_CHECK_EQUAL(cntr, graph2.OutDegree(vert));
274275
BOOST_CHECK(it == end);
275276
BOOST_CHECK(it2 == end2);
277+
BOOST_CHECK_EQUAL(it, it != end);
276278
}
277279

278280
for (const auto &vert : graph2.Vertices()) {
@@ -293,6 +295,7 @@ BOOST_AUTO_TEST_CASE(TestSparseMatrixAdapter2) {
293295
BOOST_CHECK_EQUAL(*it, *it2);
294296
BOOST_CHECK(cntr == 0U || it != begin);
295297
BOOST_CHECK(cntr == 0U || (not (it == begin)));
298+
BOOST_CHECK_EQUAL(it, it != end);
296299

297300
++cntr;
298301
++it;
@@ -303,6 +306,7 @@ BOOST_AUTO_TEST_CASE(TestSparseMatrixAdapter2) {
303306
BOOST_CHECK_EQUAL(cntr, graph2.InDegree(vert));
304307
BOOST_CHECK(it == end);
305308
BOOST_CHECK(it2 == end2);
309+
BOOST_CHECK_EQUAL(it, it != end);
306310
}
307311
}
308312
}

0 commit comments

Comments
 (0)