M
ma740988
Trying to determine how to get the max element from a complex sequence.
Given:
int main()
{
//typedef std::complex < double > C
typedef std::vector < std::complex < double > > complex_vec;
typedef complex_vec::const_iterator cvect_it;
complex_vec x_vec;
x_vec.push_back ( std::complex < double > ( 1., 2. ) );
x_vec.push_back ( std::complex < double > ( 3., 4. ) );
x_vec.push_back ( std::complex < double > ( 0, 0 ) );
x_vec.push_back ( std::complex < double > ( 4., 8. ) );
x_vec.push_back ( std::complex < double > ( 0, 0 ) );
cvect_it beg = x_vec.begin();
cvect_it end = x_vec.end();
// cvect_it iter = std::max_element ( beg, end ); // wont work
obviously ..
// std::cout << *iter << std::endl;
}
I'm perusing both forms of max_element here and I'm in a quandry how to
do this. My current solution involves copying the real values to
another vector then utilizing max_element to determine the max but I
suspect a more viable solution exists. Ideas?
Thanks in advance
Given:
int main()
{
//typedef std::complex < double > C
typedef std::vector < std::complex < double > > complex_vec;
typedef complex_vec::const_iterator cvect_it;
complex_vec x_vec;
x_vec.push_back ( std::complex < double > ( 1., 2. ) );
x_vec.push_back ( std::complex < double > ( 3., 4. ) );
x_vec.push_back ( std::complex < double > ( 0, 0 ) );
x_vec.push_back ( std::complex < double > ( 4., 8. ) );
x_vec.push_back ( std::complex < double > ( 0, 0 ) );
cvect_it beg = x_vec.begin();
cvect_it end = x_vec.end();
// cvect_it iter = std::max_element ( beg, end ); // wont work
obviously ..
// std::cout << *iter << std::endl;
}
I'm perusing both forms of max_element here and I'm in a quandry how to
do this. My current solution involves copying the real values to
another vector then utilizing max_element to determine the max but I
suspect a more viable solution exists. Ideas?
Thanks in advance