I need to come up with some code that checks if a given integer falls within the bounds of a range. (The range is represented by a pair of integers.)
So, given a range r
defined as an std::pair<int, int>
, and a test integer n
, I want to say:
if (n >= r.first && n <= r.second)
The catch is, I need to use a std::less<int>
comparison functor to do this, which means I can only work with the less than operator.
I'm trying to come up with the equivalent expression. I'm pretty sure I have it correct, but I'm not entirely confident.
The expression I came up with is:
( !cmp(n, r.first) && !cmp(r.second, n) )
where cmp
is an instance of std::less<int>
Did I do that correctly?