I\'m trying to pass function std::max
as template parameter to a templated function, but for some reasons compiler prints error that function type cannot be ded
As seen here, std::max
isn't a single, unambiguous function. At this point, it's an overload set and there are still two possibilities:
constexpr const float& max( const float& a, const float& b );
constexpr float max( std::initializer_list ilist );
You have two main options:
Cast to the appropriate type:
auto f = static_cast(std::max);
Wrap it in a lambda:
auto f = [](float a, float b) { return std::max(a, b); };
// Note there's no by-reference behaviour in this lambda.
In the future, it is expected that you will be able to do better. Today, you could emulate such a thing today with a macro (most simply done by making the macro expand into a lambda). I've come across at least one LIFT
macro that does this.