I'm trying to understand the under the hood of using const double* const
as template. I have some very basic calculation I want to perform efficiently and I don't know how the c++ compiler works(what is the assembly code).
The idea is to create a template for a function that get 3 constant doubles as template parameters and a double as an argument.
constexpr double p1 = 1;
constexpr double p2 = 2;
constexpr double p3 = 3;
template <const double* const a,
const double* const b,
const double* const c>
inline double func(double value)
{
constexpr double d = *a - *b;
constexpr double e = *a - *c;
constexpr double ratio = d / e;
constexpr double remain = *c - *a * ratio;
return value * ratio + remain;
}
double func2(double c)
{
return func<&p1,&p2,&p3>(c);
}
My question is if for every p1,p2,p3 the func< p1,p2,p3 >(c)
will be compiled to c * < const value > + < const value >
or the compiler can't extract the const values in compilation time and the full function will execute in run time.