To the best of my knowledge, the inline
keyword in c++ can be traced back to old compilers (then known as "optimizing compilers") not being able to optimize as well as modern ones, so marking a function as inline
told the compiler that this should be inlined, and as a side affect prevented ODR issues. As compilers got better, someone realized that the compilers can do a much better job of optimizing than the programmer, and so the inline
requirement of the compiler became more of a 'hint' that most (all?) modern compilers ignore.
Enter c++11 and subsequent versions. constexpr
seems to me to be in a similar situation, at least for some of its uses, specifically functions and variables. As I understand it, it tells the compiler that a certain function may be evaluated at compile time. But that is something the compiler should be able to figure out on its own. Is this feature also going to become a 'hint' once compilers get better at optimizing?
Note: I am not asking about other uses of constexpr
, such as with if
statements. I understand those are needed.