|
8 | 8 | #ifndef MCAL_MEMORY_PROGMEM_ITERATOR_2019_05_04_H |
9 | 9 | #define MCAL_MEMORY_PROGMEM_ITERATOR_2019_05_04_H |
10 | 10 |
|
11 | | - #include <iterator> |
12 | | - |
13 | | - #include <type_traits> |
14 | | - |
15 | 11 | #include <mcal_memory/mcal_memory_const_address_ptr.h> |
16 | 12 | #include <mcal_memory/mcal_memory_progmem_ptr.h> |
17 | 13 | #include <mcal_memory/mcal_memory_random_access_iterator_operations.h> |
18 | 14 |
|
| 15 | + #include <iterator> |
| 16 | + #include <type_traits> |
| 17 | + |
19 | 18 | // Implement specialized iterator types for read-only program memory. |
20 | 19 |
|
21 | 20 | namespace mcal { namespace memory { namespace progmem { |
|
53 | 52 |
|
54 | 53 | progmem_iterator(const pointer x) noexcept : current(x) { } |
55 | 54 |
|
56 | | - template<typename OtherIteratorType, |
| 55 | + template<typename OtherValueType, |
57 | 56 | typename OtherAddressType, |
58 | 57 | typename OtherAddressDifferenceType, |
59 | | - typename std::enable_if< |
60 | | - std::is_convertible<OtherIteratorType, ValueType>::value && |
| 58 | + typename std::enable_if_t< |
| 59 | + std::is_convertible<OtherValueType, ValueType>::value && |
61 | 60 | std::is_convertible<OtherAddressType, AddressType>::value && |
62 | 61 | std::is_convertible<OtherAddressDifferenceType, AddressDifferenceType>::value |
63 | | - >::type* = nullptr> |
64 | | - progmem_iterator(const progmem_iterator<OtherIteratorType, OtherAddressType, OtherAddressDifferenceType>& other) noexcept |
| 62 | + >* = nullptr> |
| 63 | + progmem_iterator(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) noexcept |
65 | 64 | : current(static_cast<const pointer>(other.current)) { } |
66 | 65 |
|
67 | 66 | auto operator*() const noexcept -> reference |
|
91 | 90 | } |
92 | 91 |
|
93 | 92 | auto operator+=(difference_type n) noexcept -> progmem_iterator& { operations::increment(current, n); return *this; } |
94 | | - auto operator-=(difference_type n) noexcept -> progmem_iterator& { current = operations::subtract(current, n); return *this; } |
| 93 | + auto operator-=(difference_type n) noexcept -> progmem_iterator& { operations::increment(current, -n); return *this; } |
| 94 | + |
| 95 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 96 | + auto operator==(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 97 | + { |
| 98 | + return (const_pointer(current) == const_pointer(other.current)); |
| 99 | + } |
| 100 | + |
| 101 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 102 | + auto operator!=(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 103 | + { |
| 104 | + return !(*this == other); |
| 105 | + } |
| 106 | + |
| 107 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 108 | + auto operator-(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept |
| 109 | + -> difference_type |
| 110 | + { |
| 111 | + return const_pointer(current) - const_pointer(other.current); |
| 112 | + } |
| 113 | + |
| 114 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 115 | + auto operator<(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 116 | + { |
| 117 | + return const_pointer(current) < const_pointer(other.current); |
| 118 | + } |
| 119 | + |
| 120 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 121 | + auto operator<=(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 122 | + { |
| 123 | + return const_pointer(current) <= const_pointer(other.current); |
| 124 | + } |
| 125 | + |
| 126 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 127 | + auto operator>(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 128 | + { |
| 129 | + return const_pointer(current) > const_pointer(other.current); |
| 130 | + } |
| 131 | + |
| 132 | + template<typename OtherValueType, typename OtherAddressType, typename OtherAddressDifferenceType> |
| 133 | + auto operator>=(const progmem_iterator<OtherValueType, OtherAddressType, OtherAddressDifferenceType>& other) const noexcept -> bool |
| 134 | + { |
| 135 | + return const_pointer(current) >= const_pointer(other.current); |
| 136 | + } |
95 | 137 |
|
96 | 138 | private: |
97 | 139 | pointer current{}; |
|
0 commit comments