Constant Fun

By Dietmar Kühl

This presentation discusses why it is useful to move some of the processing to compile time and shows some applications of doing so. In particular it shows how to create associative containers created at compile time and what is needed from the types involved to make it possible. The presentation also does some analysis to estimate the costs in terms for compile-time and object file size.

Specifically, the presentation discusses:

  • implications of static and dynamic initialization – the C++ language rules for implementing constexpr functions and classes supporting constexpr objects.

  • differences in error handling with constant expressions.

  • sorting sequences at compile time and the needed infrastructure – creating constant associative containers with compile-time and run-time look-up.

It is expected that attendees have a working knowledge of C++ but no prior knowledge of using constexpr is required. The code samples will contain lots of templates and sometimes unusual uses of the language.