There is an example in the proposal to compute the power of a number.
There is a possible application case in my current project. We have a custom type for fixed-point numbers. We have a function to compute sine and cosine for this type, thanks to a lookup table of 1024 values. This is faster (to compute) but less accurate (especially if the table is small).
We may use std::is_constant_evaluated here:
at compile-time, we can use an accurate but slow algorithm (which we don't have yet)
at runtime-time, we can keep using our current algorithm
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
That's interesting! What would be an example of where you'd want a function to change depending on whether it's compile or runtime?
There is an example in the proposal to compute the power of a number.
There is a possible application case in my current project. We have a custom type for fixed-point numbers. We have a function to compute sine and cosine for this type, thanks to a lookup table of 1024 values. This is faster (to compute) but less accurate (especially if the table is small).
We may use
std::is_constant_evaluated
here: