!= operator isn't defined for list<RooAbsData*>

Using RooFit, I get a this error when I try to iterate over list <RooAbsData*>. Am I making a mistake, or is there a reason this operator isn’t defined?

Example of code:

void loop(RooWorkspace* w){ 
  //loop over all data
  std::list< RooAbsData*> l= w->allData();

  int i=0;
  for (auto it=l.begin(); it!=l.end(); ++it){
    printf("%i\n",i++);
  }
}

I get:
Error: operator!= not defined for list<RooAbsData*,allocator<RooAbsData*> >::iterator reader.C:40:

Did you try the example or is it extracted from a larger example? Which ROOT version? Can you reproduce it with this extract only?

Reason I ask is your code looks valid on a first glance. I have copy-pasted your code to try it out, added the headers <list> and <RooWorkspace.h>, and used .L loop.C+ to check if it works. It compiles without any error message!

(Seeing list.end() in the loop header being executed multiple times always gives me a strange feeling… Even though it is constant time now, in older g++ versions is was O(n) - anyway I don’t like lists anyway!)

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