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: 
You need to return a `bool` not an `Iterator`. And you are dereferencing the `stop` iterator on the 1st loop iteration, which will be *undefined behavior* if `stop` is the `end` iterator of a container. And there is no need to dercrement the `stop` iterator at all, even though the requirement specifies it as a bidirectional iterator.

Try something more like this instead:

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

```
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(); });
}

```