Не работают алгоритмы sort и find на своем контейнере
Я пишу свой контейнер. В нем я создал итератор произвольного доступа для того, чтобы совместить контейнер с алгоритмами stl. Но когда я проверил на алгоритме sort - мне выдает ошибки:
C2672: "_Sort_unchecked":не найдена соответствующая перегруженная функция;
C2780: void std:: _Sort_unchecked(_RanIt, _Ranit, iterator_traits<_iter>::difference_type, _Pr): требуется аргументов 4, имеется 3;
C2678: бинарный "-": не найден оператор, принимающий левый операнд типа "const_RanIt"(или приемлемое преобразование отсутствует).
А когда я использую любой алгоритм find(find, find_if, find_not) - мне выдает, что элемент, который я ищу отсутствует, хотя он присутствует на самом деле. Мне, кажется, что в итераторе я перегрузил все, что только можно. Как это исправить?
#include <iostream>
#include <algorithm>
#include <iterator>
using namespace std;
template<typename T>
class Container {
public:
Container(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 : public iterator<random_access_iterator_tag, T> {
private:
T* cur;
public:
Iterator(T* cur) {
this->cur = cur;
}
Iterator operator+(int value) {
cur += value;
return *this;
}
Iterator operator-(int value) {
cur -= value;
return *this;
}
T& operator*() const {
return *cur;
}
T* operator->() const {
return cur;
}
Iterator& operator++() {
++cur;
return *this;
}
Iterator operator--() {
cur--;
return *this;
}
Iterator& operator=(T* other) {
cur = other;
return *this;
}
bool operator==(const Iterator& other) {
return this->cur = other.cur;
}
bool operator!=(const Iterator& other) {
return this->cur != other.cur;
}
bool operator>(const Iterator& other) {
return this->cur > other.cur;
}
bool operator>=(const Iterator& other) {
return this->cur >= other.cur;
}
bool operator<(const Iterator& other) {
return this->cur < other.cur;
}
bool operator<=(const Iterator& other) {
return this->cur <= other.cur;
}
};
Iterator begin()
{
return Iterator(this->array);
}
Iterator end()
{
return Iterator(this->array + this->size);
}
~Container() {
delete[] this->array;
}
private:
int size;
T* array;
};
int main() {
int size = 5;
Container<int> con(size);
for (int i = 0; i < size; i++) {
con[i] = i * 2;
}
for (int i = 0; i < size; i++) {
cout << con[i] << endl;
}
Container<int>::Iterator it = con.begin();
Container<int>::Iterator it1 = con.end();
sort(it, it1);
auto result = find(it, it1, 0);
if (result == con.end()) {
cout << "-" << endl;
}
else {
cout << "+" << endl;
}
return 0;
}