How really distinguish compile time and run time information?

  c++, compilation, metaprogramming, templates

This question might seem broad, but it really isn’t.
More specifically, if we are using templates, how do we distinguish what is compile time information and run time information?

I was watching CppCon video on the optimization and HFT systems and came across this example. If you are not familiar with high frequency trading systems, and insight is that they are really trying to squeeze the last few nanosecond from the benchmark, often violating the classy OOD principles in order to gain performance.

The example I want more to elaborate on is the following:

template<Side T>
void Strategy<T> run()
{
    const float orderPrice = calcPrice(fairValue, credit);
    //....
    sendOrder(orderPrice);
}

template<>
float Strategy<Side::buy>::calcPrice(float value, float credit)
{
    return value - credit;
}

template<>
float Strategy<Side::sell>::calcPrice(flaot value, float credit)
{
    return value + credit;
}

According to the author, this example illustrates a classical way of avoiding the run time if-else branching.
But at the time of compilation, we don’t really know whether we are going to buy or cell right? The decision is made during the run time depending on market movement.
Can someone please explain how the link between run time and compile time, specifically, how we are creating a compile time branching depending on the run time information?

Source: Windows Questions C++

LEAVE A COMMENT