CFx SDK Documentation 2024 SP0
Loading...
Searching...
No Matches
slot_iterator.h
Go to the documentation of this file.
1//
2// slot_iterator.h
3// slimsig
4//
5// Created by Christopher Tarquini on 5/20/14.
6//
7//
8
9#ifndef slimsig_slot_iterator_h
10#define slimsig_slot_iterator_h
11#include <iterator>
12#include <type_traits>
13#include <algorithm>
14namespace slimsig {
15
16
17template <class Container, class Traits = std::iterator_traits<typename Container::iterator>>
18class offset_iterator : public std::iterator<
19 typename Traits::iterator_category,
20 typename Traits::value_type,
21 typename Traits::difference_type,
22 typename Traits::pointer,
23 std::forward_iterator_tag>
24{
25using traits = std::iterator_traits<offset_iterator>;
26public:
27 using container_type = typename std::decay<Container>::type;
28 using size_type = typename Container::size_type;
29 using reference = typename traits::reference;
30 using pointer = typename traits::pointer;
31 using difference_type = typename traits::difference_type;
32 using value_type = typename traits::value_type;
33
39 bool operator ==(const offset_iterator& rhs) const {
40 return m_offset == rhs.m_offset && p_container == rhs.p_container;
41 }
42 bool operator !=(const offset_iterator rhs) const{
43 return !(*this == rhs);
44 }
45 bool operator >(const offset_iterator rhs) const{
46 return m_offset > rhs.m_offset && p_container > p_container;
47 }
48 bool operator <(const offset_iterator rhs) const{
49 return m_offset < rhs.m_offset && p_container < p_container;
50 }
51 bool operator <=(const offset_iterator rhs) const {
52 return m_offset <= rhs.m_offset && p_container <= p_container;
53 }
54 bool operator >=(const offset_iterator rhs) const {
55 return m_offset >= rhs.m_offset && p_container >= p_container;
56 }
59 return std::begin(*p_container) + m_offset;
60 }
62 return &(std::begin(*p_container) + m_offset);
63 }
65 ++m_offset;
66 return *this;
67 }
69 offset_iterator it(*this);
70 ++m_offset;
71 return it;
72 }
73 size_type size() const {
74 return p_container == nullptr ? 0 : p_container->size();
75 };
76 operator bool() const {
77 return p_container != nullptr && m_offset < p_container->size();
78 }
81};
82template <class Container, class Traits = std::iterator_traits<typename Container::iterator>>
83class slot_iterator : private offset_iterator<Container, Traits>
84{
86public:
88 using base::size_type;
89 using base::reference;
90 using base::pointer;
92 using base::value_type;
93
94 using base::base;
95 using base::operator ==;
96 using base::operator !=;
97 using base::operator >;
98 using base::operator <;
99 using base::operator >=;
100 using base::operator <=;
101 operator bool() const {
102 return bool(*this) && bool(**this);
103 }
105 do {
107 } while (bool(*this) && !(bool(**this)));
108 return *this;
109 }
111 slot_iterator it(*this);
112 ++(*this);
113 return it;
114 }
115};
116
117}
118
119#endif
offset_iterator(container_type &container, size_type offset=0)
Definition: slot_iterator.h:57
bool operator>(const offset_iterator rhs) const
Definition: slot_iterator.h:45
bool operator>=(const offset_iterator rhs) const
Definition: slot_iterator.h:54
typename Container::size_type size_type
Definition: slot_iterator.h:28
offset_iterator(const offset_iterator &)=default
typename traits::reference reference
Definition: slot_iterator.h:29
offset_iterator operator++(int)
Definition: slot_iterator.h:68
bool operator!=(const offset_iterator rhs) const
Definition: slot_iterator.h:42
typename traits::difference_type difference_type
Definition: slot_iterator.h:31
offset_iterator & operator=(const offset_iterator &)=default
offset_iterator & operator++()
Definition: slot_iterator.h:64
typename std::decay< Container >::type container_type
Definition: slot_iterator.h:27
bool operator==(const offset_iterator &rhs) const
Definition: slot_iterator.h:39
bool operator<(const offset_iterator rhs) const
Definition: slot_iterator.h:48
offset_iterator & operator=(offset_iterator &&)=default
offset_iterator(offset_iterator &&)=default
typename traits::value_type value_type
Definition: slot_iterator.h:32
bool operator<=(const offset_iterator rhs) const
Definition: slot_iterator.h:51
typename traits::pointer pointer
Definition: slot_iterator.h:30
const container_type * p_container
Definition: slot_iterator.h:79
size_type size() const
Definition: slot_iterator.h:73
slot_iterator & operator++(int)
slot_iterator & operator++()
GLintptr offset
Definition: gles2_ext.h:183