Search code examples
c++11scopervalue-referencervalue

Is there any worthwhile optimization made by declaring local values with &&


In the following member function, is there any benefit at all to declare values cc, dd, ee and ff with &&?

void doStuff(double& aa, const size_t& bb) const {
    const double&& cc = 2*bb;
    const double&& dd = 2*sumT_;
    const double&& ee = sumTsq_ - scaledTSq_;
    const double&& ff = dd*dd - 2*cc*ee;
    aa = (ff >= 0) ? (dd + sqrt(ff))/cc : std::numeric_limits<double>::infinity();
}

Why not just plain const double?


Solution

  • You are right. There is no cost difference between move and copy for double.