C++ algorithm to implement multiple operators in one
Make use of the standard library

This looks like a job for std::transform(), which in many other languages would be the equivalent of the map function. It works on iterators, so it would help if your class provides begin() and end() functions, or if internally you store values in a std::vector. However, the data pointer can be used as well.

Then, it's possible to write your operators like so:

#include &lt;algorithm&gt;

IntMatrix IntMatrix::operator&lt;(int num) const {
    IntMatrix result(width(), height()); // assuming this creates a matrix with the same dimensions
    const auto count = width() * height();
    std::transform(data, data + count, result.data,
                   [num](int value){return value &lt; num;});
    return result;
}


With this, there is no need to write your own filter() function.