Q:

convert two vector to form vector>

I have two vectors of type double and I want to combine them to make a complex vector.
vector<double> vReal;
vector<double> vImag;

How do I combine the above two to get
vector<complex<double>> vComp;

Can somebody please help me how do I do it?
Many Thanks.
Best Regards
Chintan

A:

    vComp.reserve(vReal.size());

    std::transform(
        begin(vReal), end(vReal), begin(vImag), 
        std::back_inserter(vComp), 
        [](double r, double i) { return std::complex<double>(r, i); });

