Iterating - missing iterator_category

Hello Forum,

how do I iterate over, let’s say, a list of braches?

Example code:

// Prepare example
auto t = new TTree("t","t");
Int_t i; t->Branch("someBranch", &i);
auto lbr = t->GetListOfBranches();
// No:
find_if(begin(*lbr), end(*lbr),
        [](auto o){ return o->GetName() == "someBranch"s; });

This does not work because there is no type named ‘iterator_category’ in ‘std::iterator_traits’. It seems only TIterCategory provides the traits.

So I came up with:

using ItT = remove_reference_t<decltype(*lbr)>;
find_if(TIterCategory<ItT>(lbr), TIterCategory<ItT>::End(),
        [](auto o){ return o->GetName() == "someBranch"s; }))

Is there a simpler solution?

(tree->FindBranch does not work for me, and also this problem can appear in other use cases)

auto lbr = t->GetListOfBranches();
for (auto b : *lbr)

The above should work, but I’m not sure of an easier way than yours to use *lbr with standard algorithms as you want.

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