C++ algorithm to implement multiple operators in one I have a class called IntMatrix which has 2 fields:
Dimensions dimensions;//To save height and width of my matrix
int *data;//For saving data

and I need to override the operators &gt;,&gt;=,&lt;,&lt;=,==,!= which take a scalar and compare each single value in my matrix with that scalar accordingly, and returns a new matrix with the same size that contains 1 if the comparison returned true and 0 else.
For example:
mat: {1,2,3;4,5,6}
mat_2 = mat &gt; 3;//Should return {0,0,0;1,1,1}
So, you may notice that all my functions have the exact lines of code except whenever I wrote != it should be &gt; or &lt; or == or etc....
So, in order to remove duplication here's how I implemented them:
IntMatrix IntMatrix::operator&lt;(int num) const {
    return filter(*this,Between(INT_MIN,num-1));
}

IntMatrix IntMatrix::operator&gt;(int num) const {
    return filter(*this,Between(num+1,INT_MAX));
}

IntMatrix IntMatrix::operator!=(int num) const {
    return filter(*this,Between(num,num), true);
}

where Between is a functor (to replace a pointer to a function).
So, when I reviewed my code I strongly believe this is not the best solution to give to this kind of problem, since filter() won't be well understandable by other programmers.
From your experience is there anyway to improve this code?
(I know that macros would be perfect here but don't want to use them either since they are a bad practice)
Note: I am working with C++11 and want only to use standard libraries.
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.