Any type_traits or method could find out the parameters is a constexpr or not?
Example
size_t fibo_runtime(size_t num)
{
//implementation
}
constexpr
Within the function, it isn't possible to check the parameters to see if the complete calling expression is a constant expression. But you can implement a macro at the call site to test the same thing, evaluating to true_type
or false_type
at compile time depending on whether the expression is a constant expression
IS_A_CONSTANT_EXPRESSION( fibo(5) ) // is constant
IS_A_CONSTANT_EXPRESSION( fibo(time(NULL) ) // is not constant
The details are in this answer to another question. (My own answer, apologies for cross posting!)
You could then implement another macro, FIBO( expr )
to wrap this up nicely and call the correct version as appropriate.