Go back to Richel Bilderbeek's homepage.

Go back to Richel Bilderbeek's C++ page.

 

 

 

 

 

(C++) C++11 constexpr

 

constexpr is a C++11 keyword for generalized constant expressions. In other words, constexpr indicates that an expression will always return the same values, thus rendering this return value a compile-time constant.

 

 

 

 

 

Examples

 

 

 

 

 

 

Advice

 

 

 

 

 

 

References

 

  1. GCC page about C++0x support
  2. Bjarne Stroustrup. The C++ Programming Language (4th edition). 2013. ISBN: 978-0-321-56384-2. Chapter 12.7. Advice. page 341: '[5] If a function may have to be evaluated at compile time, declare it constexpr'
  3. Scott Meyers. Effective Modern C++ (1st Edition). 2014. ISBN: 978-1-491-90399-5. Item 15 'Use constexpr whenever possible'

 

 

 

 

 

Go back to Richel Bilderbeek's C++ page.

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict