Question: This is the requirement for the code:

> 
> Create a generic function `all_equal(start, stop)` that determines
> if the elements in the range `[start,stop)` are all equal. The function returns true or false. If the range is empty, true is returned. The arguments `start` and `stop` are bidirectional iterators.
> 
> 
> 

The following is my code:

```
template <class Iterator>
Iterator all_equal(Iterator start, Iterator stop) {
    Iterator front = start;
    Iterator back = stop;
    while (front != back){
        if (*front == *back)
            return false;
        else {
            front++;
            back--;
        }
    }
}

```

The following is my feedback from a marker:

> 
> You can't dereference back. And this would compare elements two-by-two without ensuring they're all equal.
> 
> 
>

Answer: 
Solution with [`std::all_of`](https://en.cppreference.com/w/cpp/algorithm/all_any_none_of):

```
template <class Iterator>
/*constexpr*/ // in C++20
bool all_equal(Iterator begin, Iterator end)
{
    return std::all_of(begin, end, [begin](const auto& e){ return e == *begin(); });
}

```
First of all your function should return `bool` which is `true` or `false`, not iterator. Second - you cannot dereference `stop` as it does not point to an element in the sequence. Third - you either increase `start` or decrease `stop` but not both at the same time. Function could be:

```
template <class Iterator>
bool all_equal(Iterator start, Iterator stop) {
    if( start == stop ) 
        return true;
    while( true ){
        auto tmp = start++;
        if( start == stop ) return true;
        if( *tmp != *start ) return false;
    }
}

```