Skip to content

Commit 13705d3

Browse files
committed
Remove std::iterator
`std::iterator` have been deprecated in stdc++-17. It seems that the recommended usage to build custom iterators in modern C++ consists in defining type aliases with the directive `using` (see for instance the tutorial https://www.internalpointers.com/post/writing-custom-iterators-modern-cpp).
1 parent ec58d6e commit 13705d3

File tree

1 file changed

+21
-16
lines changed

1 file changed

+21
-16
lines changed

libcpputils/linq/linq_iterators.hpp

+21-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
// Copyright (c) Microsoft Open Technologies, Inc. All rights reserved. See License.txt in the project root for license information.
22

3+
#include <iterator>
34
#if !defined(CPPLINQ_LINQ_ITERATORS_HPP)
45
#define CPPLINQ_LINQ_ITERATORS_HPP
56
#pragma once
@@ -71,8 +72,8 @@ namespace cpplinq {
7172
>::type
7273
operator>=(const Iter& it, const Iter& it2) {
7374
return !(it < it2);
74-
}
75-
75+
}
76+
7677
namespace util {
7778
template <class Iter, class T>
7879
typename std::iterator_traits<Iter>::pointer deref_iterator(const Iter& it) {
@@ -88,9 +89,9 @@ namespace cpplinq {
8889
util::value_ptr<T> deref_iterator(const Iter& it, util::identity<T>) {
8990
return util::value_ptr<T>(*it);
9091
}
91-
}
92-
93-
92+
}
93+
94+
9495
template <class Iter>
9596
class iter_range
9697
{
@@ -113,16 +114,20 @@ namespace cpplinq {
113114

114115
// decays into a onepass/forward iterator
115116
template <class Cursor>
116-
class cursor_iterator
117-
: public std::iterator<std::forward_iterator_tag,
118-
typename Cursor::element_type,
119-
std::ptrdiff_t,
120-
typename std::conditional<std::is_reference<typename Cursor::reference_type>::value,
121-
typename std::add_pointer<typename Cursor::element_type>::type,
122-
util::value_ptr<typename Cursor::element_type>>::type,
123-
typename Cursor::reference_type>
117+
class cursor_iterator
124118
{
125119
public:
120+
using iterator_category = std::forward_iterator_tag;
121+
using value_type = typename Cursor::element_type;
122+
using difference_type = std::ptrdiff_t;
123+
using pointer =
124+
typename std::conditional<
125+
std::is_reference<typename Cursor::reference_type>::value,
126+
typename std::add_pointer<typename Cursor::element_type>::type,
127+
util::value_ptr<typename Cursor::element_type>
128+
>::type;
129+
using reference = typename Cursor::reference_type;
130+
126131
CPPLINQ_USE_DEFAULT_ITERATOR_OPERATORS;
127132

128133
cursor_iterator(Cursor cur) : cur(cur) {
@@ -143,7 +148,7 @@ namespace cpplinq {
143148
auto& v = **this;
144149
return &v;
145150
}
146-
151+
147152
cursor_iterator& operator++() {
148153
cur->inc();
149154

@@ -159,7 +164,7 @@ namespace cpplinq {
159164
}
160165

161166

162-
167+
163168
private:
164169
bool empty() const {
165170
return !cur || cur->empty();
@@ -176,7 +181,7 @@ namespace cpplinq {
176181
public:
177182
typedef cursor_iterator<typename Container::cursor> iterator;
178183

179-
container_range(Container c) : c(c)
184+
container_range(Container c) : c(c)
180185
{
181186
}
182187

0 commit comments

Comments
 (0)