Skip to content

Commit 67347d9

Browse files
committed
c++17 compat
1 parent 02acf2c commit 67347d9

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

src/iter.hpp

+14
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
namespace IterGen {
66

77
template <typename T> struct Iterator {
8+
#if defined(__cplusplus) && (__cplusplus == 202002L)
89
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
914
using difference_type = std::ptrdiff_t;
1015
using element_type = T;
1116
// using value_type = element_type; // ← compiler doesn't seem to need this,
@@ -62,7 +67,16 @@ template <typename T> struct Iterator {
6267

6368
reference operator[](difference_type idx) const { return _ptr[idx]; }
6469

70+
#if defined(__cplusplus) && (__cplusplus == 202002L)
6571
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
6680

6781
private:
6882
pointer _ptr;

src/main.cpp

+5
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,13 @@ int main(int argc, char *argv[]) {
1717

1818
pid_t pid = (argc > 1) ? std::stoi(argv[argc - 1]) : getpid();
1919

20+
#if defined(__cplusplus) && (__cplusplus == 202002L)
2021
static_assert(std::contiguous_iterator<Argv::Iterator>);
2122
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
2227

2328
Argv bytes = Argv::as_bytes(pid, skip, nuls);
2429

0 commit comments

Comments
 (0)