Possible to do C++ interoperation with std::function?

No, not if you are thinking of standard Fortran with its interoperability facility which is actually with a C companion processor only.

You will note std::function in C++ is a special thing, technically it is a class template for a wrapper type with polymorphism for general-purpose handling of various forms of functions including, as you noted, lamdas. Note standard Fortran does not know of basic C++ itself, let alone any interoperability with such modern features in C++.

If you remain interested in standard Fortran, your best bet is to keep it simple using C at the Fortran interface. And if you see value, consider suitable wrapping with modern C++ of this C bridge toward consumption in C++.

1 Like