What is the right way to implement the function below to allow the caller to iterate over the range it returns?
#include <set>
#include <ranges>
std::set<int> set{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
auto find_range(int a)
{
//What type should I return?
return std::make_tuple(set.lower_bound(a - 3), set.upper_bound(a + 3));
}
int main()
{
for (int x : find_range(5)) {...}
}
The function returns a couple of iterators pointing to 2 and 9, so the loop should iterate over 2, 3, 4, 5, 6, 7, 8.
setand the desired output?