top | item 37439328

(no title)

cshokie | 2 years ago

Hard-coding a relative file path seems like an obvious example. For example a config file with settings. The file will always have the same name so heap allocations and mutability are not needed.

discuss

order

eesmith|2 years ago

My config file paths have either been constant (".dotfile") or required run-time information that could not be constexpr'ed. I don't see how constexpr would be useful.

Then again, I am primarily a Python and C programmer, so there is likely some underlying reasoning I'm missing.

cshokie|2 years ago

const std::string foo = “.dot file”;

in C++ cannot change after construction, but is not compile time constant. This means that it has to run some code and allocate some memory at runtime.

In contrast constexpr is fully compile time and ends up in the read only portion of the binary. No code code execution or allocations necessary.