You want a 4096 entry tick size lookup table computed at build time so the hot path is one array index. State what makes a function usable in a constant expression, three things that silently push the table into runtime initialisation, and how you prove the bytes are in the binary.

You want a 4096 entry tick size lookup table computed at build time so the hot path is one array index. State what makes a function usable in a constant expression, three things that silently push the table into runtime initialisation, and how you prove the bytes are in the binary.

Approach: State the requirements on the function and on the object being initialised, then ask which storage duration and which initialiser actually guarantee evaluation before the program runs.

Declare the table as a constexpr array initialised by a constexpr function, and confirm it by finding the values in the read only data section of the binary with nm or objdump. A constexpr function must have a body the compiler can evaluate with no undefined behaviour, no static local, no throw on the taken path, and every call inside it usable in a constant expression too. The three silent fallbacks to runtime are declaring the object const rather than constexpr, calling a standard library function that was never marked constexpr, and a size or an input that depends on a runtime value, and in each case the compiler is permitted to emit a dynamic initialiser that runs before main. Marking the variable constexpr turns that silent fallback into a compile error, which is the whole point of writing it that way.

Follow-up: How would you get the same one-index hot path when the table size is known only from a config file read at startup?

Key concepts: constexpr, compile-time evaluation, static initialisation, read only data.