-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConstVectorIterator.h
More file actions
73 lines (57 loc) · 2.38 KB
/
ConstVectorIterator.h
File metadata and controls
73 lines (57 loc) · 2.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
//
// Created by mfbut on 11/14/2019.
//
#ifndef ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H
#define ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H
#include <iterator>
#include "ConstBaseVector.h"
namespace Matrix {
class ConstBaseVector;
class ConstVectorIterator {
public:
//the iterator type tags
using iterator_category = std::random_access_iterator_tag;
using value_type = ConstBaseVector::value_type;
using difference_type = int;
using pointer = const value_type*;
using reference = const value_type&;
//create a ConstVectorIterator over the specified vector starting at the specified position
ConstVectorIterator(const ConstBaseVector *vector, int pos);
ConstVectorIterator(const ConstVectorIterator& orig) = default;
virtual ~ConstVectorIterator() = default;
//return a reference to the element you are at
const value_type& operator*() const;
//return a reference to the element offset past your current position
const value_type& operator[](int offset) const;
//move to the next element
ConstVectorIterator& operator++(); //pre
const ConstVectorIterator operator++(int); //post
//move to the previous element
ConstVectorIterator& operator--(); //pre
const ConstVectorIterator operator--(int); //post
//move forward amount elements
ConstVectorIterator& operator+=(int amount);
ConstVectorIterator operator+(int amount) const;
//move backward amount elements
ConstVectorIterator& operator-=(int amount);
ConstVectorIterator operator-(int amount) const;
//return the number of elements between yourself and rhs
//for example if you were at element 10 and rhs was at element 7
//the difference would be 3
difference_type operator-(const ConstVectorIterator& rhs);
//you are equal to rhs if you are over the same vector
//and at the same position
bool operator==(const ConstVectorIterator& rhs) const;
bool operator!=(const ConstVectorIterator& rhs) const;
//are you at an element before rhs?
bool operator<(const ConstVectorIterator& rhs) const;
bool operator<=(const ConstVectorIterator& rhs) const;
//are you at an element after rhs?
bool operator>(const ConstVectorIterator& rhs) const;
bool operator>=(const ConstVectorIterator& rhs) const;
protected:
const ConstBaseVector* vector;
int pos;
};
}
#endif //ECS_36B_HOMEWORK_CONSTVECTORITERATOR_H