c++ - Tricky range based for loop implementation for an XML Element class in c++11 -


How can I do something like this work with range-based loops for both element and property?

  # include & lt; List & gt; #include "XMLAttribute.h" namespace XML {class element {private: typedef std :: list & lt; Specialty & gt; Attribute_container; Typedef std :: list & lt; Element & gt; Element_container; Public: XMLElement (); Bool has_attributes () const; Bull is_Elements () CONST; Bool has_data () const; Const std :: string and name () const; Const std :: string and data () const; Private: std :: string _name; Std :: string_data; Attribute_container_attributes; Element_container _elements; }; }   

I would like to be able to use something like this:

 for  (XML :: Element & el: element). } (XML :: Attribute & at: element) {..}   

and some (for auto and amp; some_name: element) {..} some block like Do // XML:: Element or XML :: Attribute? .

Is it good to implement it or should I change my design?

The correct answer is to provide an element nodes function, which return the categories of hair attributes and elements. Thus, you can do this:

  for (auto and element: element.child_elements ()) {...} (auto and attribute: element.attributes () ). ..}   

Your child_aliments function will return a type of type, which stores two iterators, such as someone. Similarly, the attributes will return a category for the attribute elements.

Comments