I wrote a container based on std::vector<std::vector<T> >
. Now I would like to have an iterator for it so I could go process it row-wise in a way I walk through a std::vector
. What is the shortest std (no boost this time) way to achieve this?
EDIT:
Actually, std::vector<std::vector<T> >
is not exactly what I have. My code looks similar to this:
struct Soldier { std::string name;};
class Platoon {
public: Soldier* commander;
std::vector<Soldier> soldiers;
};
class Company {
public: Soldier* commander;
std::vector<Platoon> platoons;
};
class Batalion {
public: Soldier* commander;
std::vector<Company> companies;
};
I have five levels of hierarchy in total, including soldiers. I would like each of these classes to have begin() and end() methods allowing iteration over soldiers, e.g. in order to:
std::for_each(bravo_company.begin(), bravo_company.end(),
front_line());