On Friday, 12 August 2016 at 14:41:14 UTC, Shachar Shemesh wrote:

That table was not expensive to compute, and its constantness wasn't crucial enough even for me to put a wrapper pointer and only access it through it. Had that not been the case, and had that table been more expensive to computer, I'd probably compute at compile time with an external tool.

Shachar

And you are forgetting about composability. If I can compute a table at compile-time this means I can go higher on the abstraction ladder.


void interpFast(string expr)(float x)
{
    // here a look-up computed at compile-time
    static immutable table = makeTable!exp(0, 100, 0.1f);
    int ipart = cast(int)x;
    int fpart = x - ipart;
    return linInterp(table[ipart], table[ipart+1], fpart);
}

void main()
{
   // automatically tabulated
   float x = interpFast!"pow(cos(x) + 4, x)"(0.5f);
}


Not only is this impossible in C++, but being cumbersome it means that people won't do it and loose optimization opportunities.

Reply via email to