I have the following C++ snippet
double exetime = 0;
SVDRec R;
{
timer<double> dummy{exetime};
R = svdLAS2();
}
std::cout << exetime << std::endl;
where the constructor of timer records the time the scoping block was entered, and its destructor (which is called when the block is leaved) computes the passed time and stores it in exetime. R is only initialized inside the block, and it does not have a default constructor, so the code doesn’t compile for this reason. But I do not want to initialize R to some dummy value.
This, too, doesn’t compile:
double exetime = 0;
SVDRec &&tmpR;
{
timer<double> dummy{exetime};
tmpR = svdLAS2();
}
SVDRec R = tmpR;
std::cout << exetime << std::endl;
I know I could use a pointer but I do not want to use dynamic allocation nor std::unique_ptr. Is there is anyway to achieve this?
You can try: