root
root copied to clipboard
[PyROOT] C++ lambda function support
Ported over from JIRA (https://its.cern.ch/jira/browse/ROOT-7704), where there was already lots of discussion. See also the previous attempt in #5541
Original ticket
Is it possibile to use lambda function created in c++ into python?
ROOT.gROOT.ProcessLine("auto l = []{cout << 100 << endl;}")
ROOT.l
I get:
/home/turra/root/lib/ROOT.py:436: RuntimeWarning: creating converter for unknown type "(lambda)"
attr = _root.LookupCppEntity( name, PyConfig.ExposeCppMacros )
I see on the contrary that it is possibile to use std::function
ROOT.gROOT.ProcessLine("std::function<void()> f = []{cout << 100 << endl;}")
ROOT.f()
the problem is that each lambda function is a different type. Is it possible to wrap them in a std::function automatically?
In master now the error is
input_line_39:2:37: error: '__cling_internal' is not a class, namespace, or enumeration
auto __cppyy_internal_wrap_l = new __cling_internal::FT<decltype(l)>::F{l};
^
input_line_39:2:37: note: '__cling_internal' declared here
it might look like progress, but we are not yet there.