Here's the code:
#include <iostream>
#include <cmath>
#include <functional>
#include <complex>
int main() {
// This works.
std::function<float(float)> f = [](auto const& x) {return std::sqrt(x);};
// This also works. Why this works?!
using Complex = std::complex<double>;
std::function<Complex(const Complex&)> g = std::sqrt<double>;
// All of the following doesn't work.
// error: conversion from ‘<unresolved overloaded function type>’
// to non-scalar type ‘std::function<float(float)>’ requested
std::function<float(float)> a = std::sqrtf<float>;
std::function<float(float)> b = std::sqrt<float>;
std::function<float(float)> c = std::sqrt;
std::function<double(double)> d = std::sqrt<double>;
}
Considering the std::sqrt reference, I am really confused as to why the one involving complex works, and why the other ones do not work.
I am aware of this question, but, I am not interested in using std::complex, and, the OP from this question specifically asks for std::complex, and, in contrast, I'd like to work only with float or double (or real valued, not complex).
What's going on? What's the correct way of doing this?