xtd 0.2.0
Loading...
Searching...
No Matches
wrap_pointer_iterator.hpp
Go to the documentation of this file.
1
4#pragma once
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 auto data() const noexcept -> const value_t& {return data_;}
83 auto data() noexcept -> value_t& {return data_;}
85
87
89 auto compare_to(const wrap_pointer_iterator& rhs) const noexcept -> int32 override {return data_ < rhs.data_ ? -1 : data_ > rhs.data_ ? 1 : 0;}
90 auto equals(const wrap_pointer_iterator& rhs) const noexcept -> bool override {return data_ == rhs.data_;}
92
94
98 auto operator *() const noexcept -> const std::remove_pointer_t<value_t>& {return *data_;}
101 auto operator *() noexcept -> std::remove_pointer_t<value_t>& {return *data_;}
104 auto operator ->() const noexcept -> const value_t& {return data_;}
107 auto operator ->() noexcept -> value_t& {return data_;}
108
111 auto operator ++() const noexcept -> wrap_pointer_iterator& {++data_; return *const_cast<wrap_pointer_iterator*>(this);}
114 auto operator ++(int) const noexcept -> wrap_pointer_iterator {auto current = *this; operator ++(); return current;}
115
118 auto operator --() const noexcept -> wrap_pointer_iterator& {--data_; return *const_cast<wrap_pointer_iterator*>(this);}
121 auto operator --(int) const noexcept -> wrap_pointer_iterator {auto current = *this; operator --(); return current;}
122
126 auto operator +(xtd::size value) const noexcept -> wrap_pointer_iterator {return wrap_pointer_iterator {data_ + value};}
130 auto operator +=(xtd::size value) noexcept -> wrap_pointer_iterator& {*this = *this + value; return *this;}
134 auto operator -(wrap_pointer_iterator value) const noexcept -> xtd::ptrdiff {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
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
auto data() const noexcept -> const value_t &
Gets iterator data.
Definition wrap_pointer_iterator.hpp:80
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
auto operator->() const noexcept -> const value_t &
Returns pointer to the current element, or a proxy holding it.
Definition wrap_pointer_iterator.hpp:104
iterator_tag_t iterator_concept
Represents the iterator concept type.
Definition wrap_pointer_iterator.hpp:45
auto operator-(wrap_pointer_iterator value) const noexcept -> xtd::ptrdiff
Subtract The specified iterator from the current iterator.
Definition wrap_pointer_iterator.hpp:134
auto operator+(xtd::size value) const noexcept -> wrap_pointer_iterator
Add operator with specified value.
Definition wrap_pointer_iterator.hpp:126
auto operator+=(xtd::size value) noexcept -> wrap_pointer_iterator &
Add equal operator with specified value.
Definition wrap_pointer_iterator.hpp:130
auto operator*() const noexcept -> const std::remove_pointer_t< value_t > &
Returns reference to the current element, or a proxy holding it.
Definition wrap_pointer_iterator.hpp:98
auto data() noexcept -> value_t &
Gets iterator data.
Definition wrap_pointer_iterator.hpp:83
auto operator--() const noexcept -> wrap_pointer_iterator &
Pre decrements the underlying iterator.
Definition wrap_pointer_iterator.hpp:118
value_t value_type
Represents the value type.
Definition wrap_pointer_iterator.hpp:41
value_type * pointer
Represents the pointer of the value type.
Definition wrap_pointer_iterator.hpp:49
auto operator++() const noexcept -> wrap_pointer_iterator &
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
size_t size
Represents a size of any object in bytes.
Definition size.hpp:23
std::int32_t int32
Represents a 32-bit signed integer.
Definition int32.hpp:23
std::ptrdiff_t ptrdiff
Represent the signed integer type of the result of subtracting two pointers.
Definition ptrdiff.hpp:23
Contains xtd::icomparable interface.
Contains xtd::iequatable interface.
The xtd::collections::generic::helpers namespace contains helpers for generic collections,...
Definition allocator.hpp:14
The xtd::collections::generic namespace contains interfaces and classes that define generic collectio...
Definition comparer.hpp:16
The xtd::collections namespace contains interfaces and classes that define various collections of obj...
Definition any_pair.hpp:10
The xtd namespace contains all fundamental classes to access Hardware, Os, System,...
Definition abstract_object.hpp:8
bool equals(const object &obj) const noexcept override
Determines whether the specified object is equal to the current object.
Definition read_only_span.hpp:272
Contains xtd::ptrdiff type.
Contains xtd::size type.