-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIter.h
More file actions
44 lines (36 loc) · 1.11 KB
/
Iter.h
File metadata and controls
44 lines (36 loc) · 1.11 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
#ifndef _Iter_H_
#define _Iter_H_
#include <iostream>
#include <vector>
#include <memory>
#include <cstddef>
/*
Acts as a pointer to the data array on the heap
Instead of passing around a raw pointer, we pass around a reference to this class
*/
class Iter{
private:
float* p;
public:
// Below setting make Iter a standard library compatible iterator
using iterator_category = std::random_access_iterator_tag;
using value_type = float; // the type of an instance of this class is equivalent to float
using difference_type = std::ptrdiff_t; // allows pointer arithmatic
using pointer = value_type*;
using reference = value_type&;
Iter(float* p_);
~Iter();
float& operator*() const;
float& operator[](int i) const;
Iter& operator++();
Iter& operator--();
Iter operator++(int);
Iter operator--(int);
Iter operator+(int i) const;
Iter operator-(int i) const;
Iter& operator+=(int i);
Iter& operator-=(int i);
bool operator==(const Iter& other) const;
bool operator!=(const Iter& other) const;
};
#endif