Skip to content

Commit 60406d2

Browse files
authored
Merge pull request #193 from Enchufa2/fix/iterator
Remove deprecated std::iterator
2 parents 9a6b24e + cdba4c6 commit 60406d2

File tree

2 files changed

+23
-16
lines changed

2 files changed

+23
-16
lines changed

NEWS.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11

22
## RcppParallel 5.1.7 (UNRELEASED)
33

4+
* Remove deprecated `std::iterator`. (#192; @Enchufa2)
5+
46
## RcppParallel 5.1.6
57

68
* Patch for TBB to allow compilation with gcc-13.

inst/include/RcppParallel/RMatrix.h

Lines changed: 21 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,21 @@ class RMatrix {
1414
public:
1515

1616
template <typename V>
17-
class row_iterator
18-
: public std::iterator<std::random_access_iterator_tag, V, std::size_t> {
17+
class row_iterator {
1918

2019
public:
21-
inline row_iterator(Row& row, std::size_t i)
20+
using iterator_category = std::random_access_iterator_tag;
21+
using value_type = V;
22+
using difference_type = std::size_t;
23+
using pointer = value_type*;
24+
using reference = value_type&;
25+
26+
inline row_iterator(Row& row, difference_type i)
2227
: start_(row.start_), parentNrow_(row.parent_.nrow()), index_(i)
2328
{
2429
}
2530

26-
inline row_iterator(V* start, std::size_t parentNrow, std::size_t index)
31+
inline row_iterator(pointer start, difference_type parentNrow, difference_type index)
2732
: start_(start), parentNrow_(parentNrow), index_(index)
2833
{
2934
}
@@ -57,23 +62,23 @@ class RMatrix {
5762
return tmp ;
5863
}
5964

60-
row_iterator operator+(std::size_t n) const {
65+
row_iterator operator+(difference_type n) const {
6166
return row_iterator(start_, parentNrow_ ,index_ + n ) ;
6267
}
63-
row_iterator operator-(std::size_t n) const {
68+
row_iterator operator-(difference_type n) const {
6469
return row_iterator(start_, parentNrow_, index_ - n ) ;
6570
}
6671

67-
std::size_t operator+(const row_iterator& other) const {
72+
difference_type operator+(const row_iterator& other) const {
6873
return index_ + other.index_;
6974
}
7075

71-
std::size_t operator-(const row_iterator& other) const {
76+
difference_type operator-(const row_iterator& other) const {
7277
return index_ - other.index_ ;
7378
}
7479

75-
row_iterator& operator+=(std::size_t n) { index_ += n ; return *this; }
76-
row_iterator& operator-=(std::size_t n) { index_ -= n ; return *this; }
80+
row_iterator& operator+=(difference_type n) { index_ += n ; return *this; }
81+
row_iterator& operator-=(difference_type n) { index_ -= n ; return *this; }
7782

7883
bool operator==(const row_iterator& other) const { return index_ == other.index_; }
7984
bool operator!=(const row_iterator& other) const { return index_ != other.index_; }
@@ -83,16 +88,16 @@ class RMatrix {
8388
bool operator>=(const row_iterator& other) const { return index_ >= other.index_; }
8489

8590

86-
inline V& operator*() { return start_[index_ * parentNrow_]; }
91+
inline reference operator*() { return start_[index_ * parentNrow_]; }
8792

88-
inline V* operator->() { return &(start_[index_ * parentNrow_]); }
93+
inline pointer operator->() { return &(start_[index_ * parentNrow_]); }
8994

90-
inline V& operator[](int i) { return start_[(index_+i) * parentNrow_]; }
95+
inline reference operator[](int i) { return start_[(index_+i) * parentNrow_]; }
9196

9297
private:
93-
V* start_;
94-
std::size_t parentNrow_;
95-
std::size_t index_;
98+
pointer start_;
99+
difference_type parentNrow_;
100+
difference_type index_;
96101
};
97102

98103
typedef row_iterator<T> iterator;

0 commit comments

Comments
 (0)