vendredi 1 juillet 2016

std::max_element on complex elements (operator= issue)

I'm trying to find the max element (based on real component of complex double) of a vector of complex doubles. The code is below:

#include <iostream>
#include <algorithm>
#include <vector>
#include <complex>

using namespace std;

int main()
{
    vector<complex<double> > rts;
    for (int i = -1; i<5; i++)
        rts.push_back(complex<double>(i,0));

    complex<double> d;
    d = std::max_element(rts.begin(), rts.end(), [](complex<double> const & lhs, complex<double> const & rhs) {return lhs.real() < rhs.real();});

    return 0;
}

I'm getting the error that

no match for ‘operator=’ (operand types are ‘std::complex’ and ‘__gnu_cxx::__normal_iterator*, std::vector > >’)|

Can anyone please help me understand what the problem is?

Thanks!

Aucun commentaire:

Enregistrer un commentaire