|
13 | 13 |
|
14 | 14 | #include <iterator>
|
15 | 15 | #include <compare>
|
| 16 | +#include <memory> |
16 | 17 |
|
17 | 18 | #include "test_iterators.h"
|
18 | 19 |
|
@@ -208,3 +209,47 @@ struct template_and_no_element_type {
|
208 | 209 | // Template param is used instead of element_type.
|
209 | 210 | static_assert(std::random_access_iterator<template_and_no_element_type<int>>);
|
210 | 211 | static_assert(std::contiguous_iterator<template_and_no_element_type<int>>);
|
| 212 | + |
| 213 | +template <bool DisableArrow, bool DisableToAddress> |
| 214 | +struct no_operator_arrow { |
| 215 | + typedef std::contiguous_iterator_tag iterator_category; |
| 216 | + typedef int value_type; |
| 217 | + typedef int element_type; |
| 218 | + typedef std::ptrdiff_t difference_type; |
| 219 | + typedef int* pointer; |
| 220 | + typedef int& reference; |
| 221 | + typedef no_operator_arrow self; |
| 222 | + |
| 223 | + no_operator_arrow(); |
| 224 | + |
| 225 | + reference operator*() const; |
| 226 | + pointer operator->() const requires (!DisableArrow); |
| 227 | + auto operator<=>(const self&) const = default; |
| 228 | + |
| 229 | + self& operator++(); |
| 230 | + self operator++(int); |
| 231 | + |
| 232 | + self& operator--(); |
| 233 | + self operator--(int); |
| 234 | + |
| 235 | + self& operator+=(difference_type n); |
| 236 | + self operator+(difference_type n) const; |
| 237 | + // Note: it's a template function to prevent a GCC warning ("friend declaration declares a non-template function"). |
| 238 | + template <bool B1, bool B2> |
| 239 | + friend no_operator_arrow<B1, B2> operator+(difference_type n, no_operator_arrow<B1, B2> x); |
| 240 | + |
| 241 | + self& operator-=(difference_type n); |
| 242 | + self operator-(difference_type n) const; |
| 243 | + difference_type operator-(const self& n) const; |
| 244 | + |
| 245 | + reference operator[](difference_type n) const; |
| 246 | +}; |
| 247 | + |
| 248 | +template<> |
| 249 | +struct std::pointer_traits<no_operator_arrow</*DisableArrow=*/true, /*DisableToAddress=*/false>> { |
| 250 | + static constexpr int *to_address(const no_operator_arrow<true, false>&); |
| 251 | +}; |
| 252 | + |
| 253 | +static_assert(std::contiguous_iterator<no_operator_arrow</*DisableArrow=*/false, /*DisableToAddress=*/true>>); |
| 254 | +static_assert(!std::contiguous_iterator<no_operator_arrow</*DisableArrow=*/true, /*DisableToAddress=*/true>>); |
| 255 | +static_assert(std::contiguous_iterator<no_operator_arrow</*DisableArrow=*/true, /*DisableToAddress=*/false>>); |
0 commit comments