Writing an iterator that makes several containers look as one

前端 未结 6 434
遇见更好的自我
遇见更好的自我 2020-12-16 12:12

Consider the following simplified example and desired output:

class A
{
    class combined_iterator
    {
        ????
    }
    typedef ??? t_combined_it;

         


        
6条回答
  •  情深已故
    2020-12-16 12:32

    boost::join is what you're looking for. You can also study the implementation, especially how to derive the lowest common denominator for container traversal, reference and return value types. To quote:

    The intention of the join function is to join two ranges into one longer range.

    The resultant range will have the lowest common traversal of the two ranges supplied as parameters.

    Note that the joined range incurs a performance cost due to the need to check if the end of a range > has been reached internally during traversal.

提交回复
热议问题