Skip to content

[PyROOT] C++ lambda function support #16168

Open
@guitargeek

Description

@guitargeek

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?

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions