0

I've looked up multiple questions related to this but haven't found a satisfying answer. So:

  • What does constexpr do, when applied to a function?
  • Why should we use constexpr on functions? What's a big difference between using it and not using it?
  • Could you provide some examples regarding constexpr functions?

I am asking this because I noticed that for example, std::array provides constexpr member functions to overload operator []. What's the reason behind having overloaded operator [] as constexpr?

Thanks in advance!

Guess
  • 135
  • 6
  • What specifically don't you understand from this: https://en.cppreference.com/w/cpp/language/constexpr (which fully defines what constexpr functions are and do, with examples) – JMAA Dec 15 '20 at 13:59
  • I do understand part of the reference, but what I don't specifically get is why and when should we use constexpr. Thanks for the answer! – Guess Dec 15 '20 at 14:00
  • 3
    Does this answer your question? [When should you use constexpr capability in C++11?](https://stackoverflow.com/questions/4748083/when-should-you-use-constexpr-capability-in-c11) – Krishna Kanth Yenumula Dec 15 '20 at 14:02

0 Answers0