In profiling my program, I realized that 10% of the code is spent on the stupid constructor std::complex<double>() using new std::complex<double>[size_of_array] .
I searched over the Internet, and the default constructor for std::complex seems to take double () as the real and imaginary parts. Since C ++ does not initialize double numbers, I wonder why g ++ is trying to initialize std::complex zeros and can I get around this through the whole program somehow (*)
(*) right now I have a special case that creates arrays of complex numbers to highlight uninitialized arrays of twins and reconstructs them as complex ones.
Edit: as indicated below, it was supervision on my side. The default constructor has empty constructors for the real and imaginary parts ( http://en.cppreference.com/w/cpp/numeric/complex/complex )
complex( const T& re = T(), const T& im = T() );
but the specification then introduces special cases for double
complex(double re = 0.0, double im = 0.0);
This special case introduces all the overhead because it bypasses the actual default constructor "double", which does nothing (the same as for int, long, float, etc.).
c ++ c ++ 11 default-constructor
Juanjo
source share