I have the following code, it works, but C++20 version does not look much better than C++17 version. My guess issue is that multimap
equal_range
returns a pair
and ranges can not figure out that is a pair of valid iterators.
Is there a way to write this in a shorter nicer way?
#include <iostream>
#include <map>
#include <ranges>
int main() {
std::multimap<bool,int> oddness{{false,2}, {true,3}, {true,47}, {false,74656}};
// nice, does not work:
// oddness.equal_range(true) | std::views::values;
// works:
oddness | std::views::values;
// working code:
auto odds = oddness.equal_range(true);
const auto odds_view = std::views::values(std::ranges::subrange(odds.first, odds.second));
for (const auto& odd : odds_view) {
std::cout << odd << std::endl;
}
}