Go back to Richel Bilderbeek's homepage.

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

 

 

 

 

 

(C++) constexpr

 

constexpr is a keyword that has different meanings, depending on the standard used:

 

 

 

 

 

C++98 constexpr in the C++98 standard

 

constexpr is not supported in C++98.

 

 

 

 

 

C++0x constexpr in the C++0x standard

 

 

An constexpr is a 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. The example below shows that such a compile-time constant can be used to indicate an array size:

 

constexpr int get_size() { return 3; }

int main()
{
  int my_array[ get_size() ];
}

 

 

 

 

 

References

 

  1. GCC page about C++0x support

 

 

 

 

 

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

Go back to Richel Bilderbeek's homepage.

 

Valid XHTML 1.0 Strict