|
11 | 11 |
|
12 | 12 | #include <cstddef> |
13 | 13 | #include <iterator> |
| 14 | +#include <algorithm> |
14 | 15 |
|
15 | 16 | namespace xt |
16 | 17 | { |
17 | 18 |
|
18 | 19 | template <class T> |
19 | 20 | class pybuffer_adaptor |
20 | 21 | { |
21 | | - |
22 | 22 | public: |
23 | 23 |
|
24 | 24 | using value_type = T; |
@@ -72,6 +72,24 @@ namespace xt |
72 | 72 | size_type m_size; |
73 | 73 | }; |
74 | 74 |
|
| 75 | + template<class T> |
| 76 | + bool operator==(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 77 | + |
| 78 | + template<class T> |
| 79 | + bool operator<(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 80 | + |
| 81 | + template<class T> |
| 82 | + bool operator!=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 83 | + |
| 84 | + template<class T> |
| 85 | + bool operator>(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 86 | + |
| 87 | + template<class T> |
| 88 | + bool operator<=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 89 | + |
| 90 | + template<class T> |
| 91 | + bool operator>=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y); |
| 92 | + |
75 | 93 | template <std::size_t N> |
76 | 94 | class pystrides_iterator; |
77 | 95 |
|
@@ -110,7 +128,7 @@ namespace xt |
110 | 128 | const_pointer p_data; |
111 | 129 | size_type m_size; |
112 | 130 | }; |
113 | | - |
| 131 | + |
114 | 132 | /*********************************** |
115 | 133 | * pybuffer_adaptor implementation * |
116 | 134 | ***********************************/ |
@@ -240,7 +258,43 @@ namespace xt |
240 | 258 | { |
241 | 259 | return rend(); |
242 | 260 | } |
243 | | - |
| 261 | + |
| 262 | + template<class T> |
| 263 | + inline bool operator==(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 264 | + { |
| 265 | + return (x.size() == y.size() && std::equal(x.begin(), x.end(), y.begin())); |
| 266 | + } |
| 267 | + |
| 268 | + template<class T> |
| 269 | + inline bool operator<(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 270 | + { |
| 271 | + return std::lexicographical_compare(x.begin(), x.end(), y.begin(), y.end()); |
| 272 | + } |
| 273 | + |
| 274 | + template<class T> |
| 275 | + inline bool operator!=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 276 | + { |
| 277 | + return !(x == y); |
| 278 | + } |
| 279 | + |
| 280 | + template<class T> |
| 281 | + inline bool operator>(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 282 | + { |
| 283 | + return y < x; |
| 284 | + } |
| 285 | + |
| 286 | + template<class T> |
| 287 | + inline bool operator<=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 288 | + { |
| 289 | + return !(y < x); |
| 290 | + } |
| 291 | + |
| 292 | + template<class T> |
| 293 | + inline bool operator>=(const pybuffer_adaptor<T>& x, const pybuffer_adaptor<T>& y) |
| 294 | + { |
| 295 | + return !(x < y); |
| 296 | + } |
| 297 | + |
244 | 298 | /************************************* |
245 | 299 | * pystrides_iterator implementation * |
246 | 300 | *************************************/ |
|
0 commit comments