xtd 0.2.0
wrap_pointer_iterator.hpp
Go to the documentation of this file.
1
4#pragma once
5#include "../../../icomparable.hpp"
6#include "../../../iequatable.hpp"
7#include "../../../ptrdiff.hpp"
8#include "../../../size.hpp"
9#include <iterator>
10
12namespace xtd {
14 namespace collections {
16 namespace generic {
18 namespace helpers {
34 template<class value_t, class iterator_tag_t = std::bidirectional_iterator_tag>
35 class wrap_pointer_iterator : public xtd::icomparable<wrap_pointer_iterator<value_t, iterator_tag_t>>, public xtd::iequatable<wrap_pointer_iterator<value_t, iterator_tag_t>> {
36 public:
38
41 using value_type = value_t;
43 using iterator_category = iterator_tag_t;
45 using iterator_concept = iterator_tag_t;
51 using const_pointer = const value_type*;
57
59
65 explicit wrap_pointer_iterator(value_t pointer) noexcept : data_ {pointer} {}
67
69 wrap_pointer_iterator(const wrap_pointer_iterator& value) noexcept = default;
70 wrap_pointer_iterator& operator =(const wrap_pointer_iterator& value) noexcept = default;
71 wrap_pointer_iterator(wrap_pointer_iterator&& value) noexcept = default;
72 wrap_pointer_iterator& operator =(wrap_pointer_iterator&& value) noexcept = default;
74
76
80 const value_t& data() const noexcept {return data_;}
83 value_t& data() noexcept {return data_;}
85
87
89 int32 compare_to(const wrap_pointer_iterator& rhs) const noexcept override {return data_ < rhs.data_ ? -1 : data_ > rhs.data_ ? 1 : 0;}
90 bool equals(const wrap_pointer_iterator& rhs) const noexcept override {return data_ == rhs.data_;}
92
94
98 const std::remove_pointer_t<value_t>& operator *() const noexcept {return *data_;}
101 std::remove_pointer_t<value_t>& operator *() noexcept {return *data_;}
104 const value_t& operator ->() const noexcept {return data_;}
107 value_t& operator ->() noexcept {return data_;}
108
111 wrap_pointer_iterator& operator ++() const noexcept {++data_; return *const_cast<wrap_pointer_iterator*>(this);}
114 wrap_pointer_iterator operator ++(int) const noexcept {auto current = *this; operator ++(); return current;}
115
118 wrap_pointer_iterator& operator --() const noexcept {--data_; return *const_cast<wrap_pointer_iterator*>(this);}
121 wrap_pointer_iterator operator --(int) const noexcept {auto current = *this; operator --(); return current;}
122
126 wrap_pointer_iterator operator +(xtd::size value) const noexcept {return wrap_pointer_iterator {data_ + value};}
130 wrap_pointer_iterator& operator +=(xtd::size value) noexcept {*this = *this + value; return *this;}
134 xtd::ptrdiff operator -(wrap_pointer_iterator value) const noexcept {return data_ - value.data_;}
136
137 private:
138 mutable value_t data_ = nullptr;
139 };
140 }
141 }
142 }
143}
Represents a wrap pointer iterator.
Definition wrap_pointer_iterator.hpp:35
xtd::ptrdiff operator-(wrap_pointer_iterator value) const noexcept
Subtract The specified iterator from the current iterator.
Definition wrap_pointer_iterator.hpp:134
wrap_pointer_iterator operator+(xtd::size value) const noexcept
Add operator with specified value.
Definition wrap_pointer_iterator.hpp:126
const std::remove_pointer_t< value_t > & operator*() const noexcept
Returns reference to the current element, or a proxy holding it.
Definition wrap_pointer_iterator.hpp:98
wrap_pointer_iterator & operator+=(xtd::size value) noexcept
Add equal operator with specified value.
Definition wrap_pointer_iterator.hpp:130
wrap_pointer_iterator(value_t pointer) noexcept
Initializes a new instance of the xtd::collections::generic::helpers::wrap_pointer_iterator class wit...
Definition wrap_pointer_iterator.hpp:65
const value_type * const_pointer
Represents the const pointer of the value type.
Definition wrap_pointer_iterator.hpp:51
xtd::ptrdiff difference_type
Represents the value type.
Definition wrap_pointer_iterator.hpp:47
value_type & reference
Represents the reference of the value type.
Definition wrap_pointer_iterator.hpp:53
iterator_tag_t iterator_concept
Represents the iterator concept type.
Definition wrap_pointer_iterator.hpp:45
wrap_pointer_iterator & operator--() const noexcept
Pre decrements the underlying iterator.
Definition wrap_pointer_iterator.hpp:118
const value_t & operator->() const noexcept
Returns pointer to the current element, or a proxy holding it.
Definition wrap_pointer_iterator.hpp:104
value_t & data() noexcept
Gets iterator data.
Definition wrap_pointer_iterator.hpp:83
value_t value_type
Represents the value type.
Definition wrap_pointer_iterator.hpp:41
const value_t & data() const noexcept
Gets iterator data.
Definition wrap_pointer_iterator.hpp:80
value_type * pointer
Represents the pointer of the value type.
Definition wrap_pointer_iterator.hpp:49
wrap_pointer_iterator & operator++() const noexcept
Pre increments the underlying iterator.
Definition wrap_pointer_iterator.hpp:111
iterator_tag_t iterator_category
Represents the iterator category type.
Definition wrap_pointer_iterator.hpp:43
const value_type & const_reference
Represents the const reference of the value type.
Definition wrap_pointer_iterator.hpp:55
wrap_pointer_iterator()=default
Initializes a new instance of the xtd::collections::generic::helpers::wrap_pointer_iterator class.
Defines a generalized comparison method that a value type or class implements to create a type-specif...
Definition icomparable.hpp:21
Defines a generalized method that a value type or class implements to create a type-specific method f...
Definition iequatable.hpp:22
int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition xtd_about_box.hpp:10