I'm trying to wrap my head around how ranges work. The following code seems natural to me:
#include <algorithm>
#include <map>
#include <ranges>
int main()
{
std::multimap<int, int> a{
{ 1, 2 },
{ 1, 3 },
{ 4, 5 },
{ 4, 6 },
};
const auto [b, c] = a.equal_range(a.cbegin()->first);
auto d = std::ranges::min(std::ranges::subrange{ b, c }, {}, &decltype(a)::value_type::second);
}
But it won't compile with this error (shortened):
main.cpp(14,24): error C2672: 'operator __surrogate_func': no matching overloaded function found
main.cpp(14,95): error C7602: 'std::ranges::_Min_fn::operator ()': the associated constraints are not satisfied
algorithm(9663): message : see declaration of 'std::ranges::_Min_fn::operator ()'
So my question is, why not? And what should I do differently to make this work?
So to be clear, of all the elements in the multimap associated with the first key, I want the element with the lowest value.
I'm compiling with Visual Studio 2019 16.11.1 with the /std:c++latest
flag.