Obecně velmi obtížně. Ale třeba pro hledání fixed point ≥ 0 funkce constexpr int(int) lze napsat něco takového:
template <int(*func)(int),
int point,
bool fixed>
struct find_fix;
// point není fixed, zkusí point + 1
template <int(*func)(int),
int point>
struct find_fix<func, point, false>
: find_fix<func, point + 1, point + 1 == func(point + 1)>
{};
// point je fixed
template <int(*func)(int),
int point>
struct find_fix<func, point, true>
{
static constexpr int value = point;
};
template <int(*func)(int)>
int fix()
{
return find_fix<func, 0, func(0) == 0>::value;
}
// Zkouška, fixed point je 42:
constexpr int test(int i)
{
return i != 42 ? i + 1 : i;
}
int main()
{
std::cout << fix<test>() << std::endl;
}