Std :: complex in a struct making compilation slow

I noticed that the following code is very slow to compile: (it can't even finish on my computer)

#include <complex>

struct some_big_struct {
    std::complex <double> a[1000000][2];
};

some_big_struct a;

int main () {
    return 0;
}

      

Out of curiosity, I've also tried other variations of the code. However, these codes seem to compile very well on my computer:

#include <complex>

struct some_big_struct {
    double a[1000000][2];
};

some_big_struct a;

int main () {
    return 0;
}

      

and

#include <complex>

std::complex <double> a[1000000][2];

int main () {
    return 0;
}

      

I wonder if anyone can elaborate on why this is the case. Thank!

+3


source to share


1 answer


During compilation, the default constructor probably works std::complex

, so it can put the initialized values โ€‹โ€‹of all array members in the executable file, rather than generate code that executes this loop when the program starts. So it calls the constructor 2 million times during compilation.



+3


source







All Articles