PIVector iterator operators
This commit is contained in:
@@ -227,12 +227,31 @@ public:
|
|||||||
inline iterator(): parent(0), pos(0) {}
|
inline iterator(): parent(0), pos(0) {}
|
||||||
inline T & operator *() {return (*parent)[pos];}
|
inline T & operator *() {return (*parent)[pos];}
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {return (*parent)[pos];}
|
||||||
inline void operator ++() {++pos;}
|
inline T & operator->() {return (*parent)[pos];}
|
||||||
inline void operator ++(int) {++pos;}
|
|
||||||
inline void operator --() {--pos;}
|
inline iterator & operator ++() {++pos; return *this;}
|
||||||
inline void operator --(int) {--pos;}
|
inline iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
||||||
|
inline iterator & operator --() {--pos; return *this;}
|
||||||
|
inline iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
||||||
|
|
||||||
|
inline iterator & operator +=(const iterator & it) {pos += it.pos; return *this;}
|
||||||
|
inline iterator & operator +=(size_t p) {pos += p; return *this;}
|
||||||
|
inline iterator & operator -=(const iterator & it) {pos -= it.pos; return *this;}
|
||||||
|
inline iterator & operator -=(size_t p) {pos -= p; return *this;}
|
||||||
|
|
||||||
|
friend inline iterator operator-(const iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
||||||
|
friend inline iterator operator-(size_t p, const iterator & it) {return it - p;}
|
||||||
|
friend inline size_t operator-(const iterator & it1, const iterator & it2) {return it1.pos - it2.pos;}
|
||||||
|
|
||||||
|
friend inline iterator operator+(const iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
||||||
|
friend inline iterator operator+(size_t p, const iterator & it) {return it + p;}
|
||||||
|
|
||||||
inline bool operator ==(const iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const iterator & it) const {return (pos == it.pos);}
|
||||||
inline bool operator !=(const iterator & it) const {return (pos != it.pos);}
|
inline bool operator !=(const iterator & it) const {return (pos != it.pos);}
|
||||||
|
friend inline bool operator <(const iterator & it1, const iterator & it2) {return it1.pos < it2.pos;}
|
||||||
|
friend inline bool operator <=(const iterator & it1, const iterator & it2) {return it1.pos <= it2.pos;}
|
||||||
|
friend inline bool operator >(const iterator & it1, const iterator & it2) {return it1.pos > it2.pos;}
|
||||||
|
friend inline bool operator >=(const iterator & it1, const iterator & it2) {return it1.pos >= it2.pos;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class const_iterator {
|
class const_iterator {
|
||||||
@@ -244,12 +263,31 @@ public:
|
|||||||
public:
|
public:
|
||||||
inline const_iterator(): parent(0), pos(0) {}
|
inline const_iterator(): parent(0), pos(0) {}
|
||||||
inline const T & operator *() const {return (*parent)[pos];}
|
inline const T & operator *() const {return (*parent)[pos];}
|
||||||
inline void operator ++() {++pos;}
|
inline const T & operator->() {return (*parent)[pos];}
|
||||||
inline void operator ++(int) {++pos;}
|
|
||||||
inline void operator --() {--pos;}
|
inline const_iterator & operator ++() {++pos; return *this;}
|
||||||
inline void operator --(int) {--pos;}
|
inline const_iterator & operator ++(int) {const auto tmp = *this; ++*this; return tmp;}
|
||||||
|
inline const_iterator & operator --() {--pos; return *this;}
|
||||||
|
inline const_iterator & operator --(int) {const auto tmp = *this; --*this; return tmp;}
|
||||||
|
|
||||||
|
inline const_iterator & operator +=(const const_iterator & it) {pos += it.pos; return *this;}
|
||||||
|
inline const_iterator & operator +=(size_t p) {pos += p; return *this;}
|
||||||
|
inline const_iterator & operator -=(const const_iterator & it) {pos -= it.pos; return *this;}
|
||||||
|
inline const_iterator & operator -=(size_t p) {pos -= p; return *this;}
|
||||||
|
|
||||||
|
friend inline const_iterator operator-(const const_iterator & it, size_t p) {auto tmp = it; tmp -= p; return tmp;}
|
||||||
|
friend inline const_iterator operator-(size_t p, const const_iterator & it) {return it - p;}
|
||||||
|
friend inline size_t operator-(const const_iterator & it1, const const_iterator & it2) {return it1.pos - it2.pos;}
|
||||||
|
|
||||||
|
friend inline const_iterator operator+(const const_iterator & it, size_t p) {auto tmp = it; tmp += p; return tmp;}
|
||||||
|
friend inline const_iterator operator+(size_t p, const const_iterator & it) {return it + p;}
|
||||||
|
|
||||||
inline bool operator ==(const const_iterator & it) const {return (pos == it.pos);}
|
inline bool operator ==(const const_iterator & it) const {return (pos == it.pos);}
|
||||||
inline bool operator !=(const const_iterator & it) const {return (pos != it.pos);}
|
inline bool operator !=(const const_iterator & it) const {return (pos != it.pos);}
|
||||||
|
friend inline bool operator <(const const_iterator & it1, const const_iterator & it2) {return it1.pos < it2.pos;}
|
||||||
|
friend inline bool operator <=(const const_iterator & it1, const const_iterator & it2) {return it1.pos <= it2.pos;}
|
||||||
|
friend inline bool operator >(const const_iterator & it1, const const_iterator & it2) {return it1.pos > it2.pos;}
|
||||||
|
friend inline bool operator >=(const const_iterator & it1, const const_iterator & it2) {return it1.pos >= it2.pos;}
|
||||||
};
|
};
|
||||||
|
|
||||||
class reverse_iterator {
|
class reverse_iterator {
|
||||||
|
|||||||
@@ -130,8 +130,8 @@ public:
|
|||||||
virtual const char * parentClassName() const {return "";}
|
virtual const char * parentClassName() const {return "";}
|
||||||
|
|
||||||
|
|
||||||
//! \~english Return if debug of this object is active
|
//! \~english Return if \a piCoutObj of this object is active
|
||||||
//! \~russian Возвращает включен ли вывод на консоль для этого объекта
|
//! \~russian Возвращает включен ли вывод \a piCoutObj для этого объекта
|
||||||
bool debug() const {return property(PIStringAscii("debug")).toBool();}
|
bool debug() const {return property(PIStringAscii("debug")).toBool();}
|
||||||
|
|
||||||
|
|
||||||
@@ -140,8 +140,8 @@ public:
|
|||||||
void setName(const PIString & name) {setProperty(PIStringAscii("name"), name);}
|
void setName(const PIString & name) {setProperty(PIStringAscii("name"), name);}
|
||||||
void setName(const char * name) {setName(PIStringAscii(name));}
|
void setName(const char * name) {setName(PIStringAscii(name));}
|
||||||
|
|
||||||
//! \~english Set object debug active
|
//! \~english Set object \a piCoutObj active
|
||||||
//! \~russian Включает или отключает вывод на консоль для этого объекта
|
//! \~russian Включает или отключает вывод \a piCoutObj для этого объекта
|
||||||
void setDebug(bool debug) {setProperty(PIStringAscii("debug"), debug);}
|
void setDebug(bool debug) {setProperty(PIStringAscii("debug"), debug);}
|
||||||
|
|
||||||
//! \~english Returns properties of the object
|
//! \~english Returns properties of the object
|
||||||
|
|||||||
10
main.cpp
10
main.cpp
@@ -1,13 +1,13 @@
|
|||||||
#include "pip.h"
|
#include "pip.h"
|
||||||
|
#include <algorithm>
|
||||||
|
|
||||||
int main(int argc, char * argv[]) {
|
int main(int argc, char * argv[]) {
|
||||||
PIVector <int> v(5, [](size_t i){return i*2;});
|
PIVector <int> v(5, [](size_t i){return i*2;});
|
||||||
v.prepend({1, 2, 3});
|
v.prepend({1, 2, 3});
|
||||||
piCout << v;
|
piCout << v;
|
||||||
piCout << v.reduce<int>([](int v, int s){return v+s;});
|
for (auto i: v) piCout << i;
|
||||||
piCout << v.reduce<PIString>([](int v, PIString s){return s+PIString::fromNumber(v);});
|
piCout << "sz" << v.end() - v.begin();
|
||||||
PIStringList sl = v.map<PIString>([](int v){return PIString::fromNumber(v);});
|
std::sort(v.begin(), v.end());
|
||||||
piCout << sl;
|
piCout << v;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user