I have a vector of complex numbers and I need to sort them by their argument. Sadly, the numbers have type complex<int>
, so function arg(c)
returns an integer in range [-3,3] instead of a float and the numbers can't be sorted properly.
I've tried also
typedef complex<int> ci;
typedef complex<double> cd;
vector<ci> a;
sort(a.begin(), a.end(), [](ci v, ci u) { return arg(cd(v)) < arg(cd(u)); });
but it does not work either (compilation error: no matching function for call to ‘std::complex<double>::complex(ci&)
).
Can I sort these numbers without changing their type?