user877329
user877329

Reputation: 6200

Loop over internal complex container

Suppose a class like

class Foo
    {
    private:
        ANonTrivialContainer bar;
        OtherData baz;
    };

The iterators of ANonTrivialContainer are bi-directional. From outside, I want to do stuff with the contents of bar. What is prefferable of

Upvotes: 1

Views: 79

Answers (1)

Massa
Massa

Reputation: 8972

I would provide a visitBars generic method, taking a functor as the parameter.

template<typename F> void visitBars(F visit) {
  for(auto b: bar)
    visit(b);
}

Upvotes: 1

Related Questions