RDataframe cannot be captured because it does not have automatic storage duration

Hello,

I am attempting to pass external variables into the lambda function for my RDataframe object, I am working on a simple test using python and the c++ snippet is written:

ROOT.gInterpreter.Declare(
    '''
    std::string hh="hello";
    auto flipper = [&hh]( double pt_in , double eta_in ) {
            std::cout<<hh<<std::endl;
            std::cout<<"test"<<std::endl;
            return pt_in;
        };
    '''
    )

However I have gotten the error:
error: ‘hh’ cannot be captured because it does not have automatic storage duration

if i go full fledged c++ it work. Is this behavior expected? thanks.

Siewyan

ROOT Version: 6.22
Platform: Not Provided
Compiler: Not Provided


Hi,
in that context hh is at global scope, and therefore can’t be captured like that. You can simply use it in the body of the lambda (i.e. just remove the capture), it will work. A compiled C++ reproducer here.

Cheers,
Enrico

1 Like

Thanks you @eguiraud, that solved the problem!

Siewyan

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.