Search code examples
c++c++20template-specialization

Is it permissible to specialize mathematical constants for custom numeric types?


Suppose I create my own floating point type MyFloatingPoint (e.g. to provide increased precision relative to the built-in types). Is it permissible to specialize the constants in the C++20 <numbers> header for this type, or is this undefined behavior?


Solution

  • According to C++20 draft it seems fine:

    26.9.2 (...) 2. Pursuant to 16.5.4.2.1, a program may partially or explicitly specialize a mathematical constant variable template provided that the specialization depends on a program-defined type