samedi 1 avril 2017

Can C++ compilers cache constexpr functions?

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 in some sort of map.

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 templates? Are constexpr values on templates cachable or do they also have to be recalculated each time?

Aucun commentaire:

Enregistrer un commentaire