What is needed for range-based for loops on TCollections?

Hi, I’m wondering what kind of changes would be needed in order to be able to use the C++11 range-based for loops for ROOT containers like TObjArray.

I know what are the requirements for a home-spun container class from online tutorials, but honestly the ROOT containers are confusing to figure out. It seems that they have their own TIterator (& children) classes, but that these are not following the usual rules for C++ STL iterators. I understand that these probably came about before the STL and such, but there must be a way to modify them (or add new compliant iterators) in order to allow users to do: for(auto obj : objarray).

I am willing to volunteer some time to submit patches, but I need to be pointed in the right direction.


Hi Jean-François,

to take advantage of the range based loops, in C++11, the container must for example provide a begin and end methods: en.cppreference.com/w/cpp/language/range-for .
The TCollection abstract class provides those methods in the ROOT6 series and therefore also TObjArray.
Did you encounter problems using it?