#include <iostream>
#include <algorithm>
using namespace std;
template<typename T>
class MyContainer {
public:
MyContainer(int size) {
this->size = size;
this->array = new T[this->size];
}
T& operator[](int index) {
if (index >= this->size || index < 0) {
cout << "Error, index was out of range!!!" << endl;
return this->array[0];
}
return this->array[index];
}
class Iterator;
Iterator begin() { return this->array; }
Iterator end() { return this->array + this->size; }
class Iterator
{
private:
T* cur;
public:
Iterator(T *first) : cur(first)
{}
T& operator+ (int n) { return *(cur + n); }
T& operator- (int n) { return *(cur - n); }
Iterator operator++ (int) { return cur++; }
Iterator operator-- (int) { return cur--; }
Iterator& operator++ () { ++cur; return *this; }
Iterator& operator-- () { --cur; return *this; }
bool operator!= (const Iterator& it) { return cur != it.cur; }
bool operator== (const Iterator& it) { return cur == it.cur; }
T& operator* () { return *cur; }
};
~MyContainer() {
delete[] this->array;
}
private:
int size;
T* array;
};
int main() {
int size = 5;
MyContainer<int> Con(size);
for (int i = 0; i < size; i++) {
Con[i] = i * 2;
}
cout << endl << endl;
auto it1 = MyContainer<int>::Iterator(Con.begin());
auto it2 = MyContainer<int>::Iterator(Con.end());
auto result = max_element(it1, it2);
cout << *result << endl;
return 0;
}