I'm trying to find the intersection of two ranges in C++? For example, if I have one range as [1..14] inclusive, and another as [10..20] inclusive, I want to get [10..14], as that is the intersection between them.
I found a way on SO as follows :
intersection = { std::max(arg1.min, arg2.min), std::min(arg1.max, arg2.max) };
if (intersection.max < intersection.min) {
intersection.markAsEmpty();
}
I have few variables as follows :
unsigned long long int min1,min2,max1,max2
for which I'm trying to find the the intersection. Then I did the following:
intersection = { std::max(min1, min2), std::min(max1, max2) };
if (intersection.max < intersection.min) {
intersection.markAsEmpty();
}
But this gives the error that unsigned long long int can't be used. How do I use it find the intersection ?