File tree 2 files changed +19
-0
lines changed
2 files changed +19
-0
lines changed Original file line number Diff line number Diff line change 5
5
namespace IterGen {
6
6
7
7
template <typename T> struct Iterator {
8
+ #if defined(__cplusplus) && (__cplusplus == 202002L)
8
9
using iterator_concept [[maybe_unused]] = std::contiguous_iterator_tag;
10
+ #else
11
+ // strongest type of iterator in c++17
12
+ using iterator_category = std::random_access_iterator_tag;
13
+ #endif
9
14
using difference_type = std::ptrdiff_t ;
10
15
using element_type = T;
11
16
// using value_type = element_type; // ← compiler doesn't seem to need this,
@@ -62,7 +67,16 @@ template <typename T> struct Iterator {
62
67
63
68
reference operator [](difference_type idx) const { return _ptr[idx]; }
64
69
70
+ #if defined(__cplusplus) && (__cplusplus == 202002L)
65
71
auto operator <=>(const Iterator &) const = default ;
72
+ #else
73
+ bool operator ==(const Iterator &other) const { return other._ptr == _ptr; }
74
+ bool operator !=(const Iterator &other) const { return other._ptr != _ptr; }
75
+ bool operator <=(const Iterator &other) const { return other._ptr <= _ptr; }
76
+ bool operator <(const Iterator &other) const { return other._ptr < _ptr; }
77
+ bool operator >=(const Iterator &other) const { return other._ptr >= _ptr; }
78
+ bool operator >(const Iterator &other) const { return other._ptr > _ptr; }
79
+ #endif
66
80
67
81
private:
68
82
pointer _ptr;
Original file line number Diff line number Diff line change @@ -17,8 +17,13 @@ int main(int argc, char *argv[]) {
17
17
18
18
pid_t pid = (argc > 1 ) ? std::stoi (argv[argc - 1 ]) : getpid ();
19
19
20
+ #if defined(__cplusplus) && (__cplusplus == 202002L)
20
21
static_assert (std::contiguous_iterator<Argv::Iterator>);
21
22
static_assert (std::contiguous_iterator<ArgvArgc::Iterator>);
23
+ #else
24
+ static_assert (std::is_same<std::random_access_iterator_tag, Argv::Iterator::iterator_category>::value);
25
+ static_assert (std::is_same<std::random_access_iterator_tag, ArgvArgc::Iterator::iterator_category>::value);
26
+ #endif
22
27
23
28
Argv bytes = Argv::as_bytes (pid, skip, nuls);
24
29
You can’t perform that action at this time.
0 commit comments