Disclaimer: This question is a bit complicated because it's several questions in one, but they're all related to the same sort of concept/issue.
Premise:
consexpr
functions may only consist of a single return
statement.
They can call other functions and use conditionals, but theoretically they should demonstrate functional purity, and thus the results should be cachable (by the compiler, at compile time) in some sort of map so that the compiler doesn't have to constantly re-evaluate the same function.
Question(s):
Is this assumption correct or is there something I haven't considered that makes it impossible to cache the result of a constexpr
function?
If no, does this mean that constexpr
functions have to be calculated every time they're used?
What about template
s? Are constexpr
values on template
s cachable or do they also have to be recalculated each time?