5 ms·
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 allocat
by cshokie 3y 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.
- eesmith 3y agoMy 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 3y agoconst 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.