mercredi 19 septembre 2018

Can't compile on std::min_element's return

#include <map>
#include <iostream>
#include <algorithm>

using namespace std;

int main()
{
    std::map<double, double> A;

    const auto it = std::min_element(A.begin(), A.end(),
                                [](decltype(A)::value_type& l, decltype(A)::value_type& r) -> bool { return l.second < r.second; });

    std::cout << *it << std::endl;
}

I wish to compute the minimum in the map.

This code failed to compile. I thought the way to use std::min_element's returned iterator is by referencing it. No?

The error message on the std::cout line is "invalid operands to binary expression".

Aucun commentaire:

Enregistrer un commentaire