Suppose I have a template function:
template <typename T, T value>
auto foo(std::integral_constant<T, value>)
{
if constexpr (value == 0)
{
return int{};
}
else
{
return float{};
}
}
And I want to call it using a number constant:
foo(4);
Can it be implemented? If no, why?
I see that I can create std::integral_constant on my own, but I'm interested in the idea of creating a type from an object. In the example above, I have 4 as the object and std::integral_constant as the type.
Declaring some define which will do if or switch is not a solution - it will be a lot of code and slow.