Boost logo

Boost :

From: Craig Henderson (craigh_at_[hidden])
Date: 2001-02-27 05:11:19


Thanks for your replies. I have gotten around the problem by introducing a
new for_each template as below. I would be interested to hear any comments
about this approach (I am still fairly new at this generic programming). I
guess the biggest disadvantage of this method is that the outer container
must implement an operator() to return a pointer to the inner container ;(

Here's the code. Thanks for your time

// _IC = Inner Container type (eg std::list<Group>)
// _OC = Outer Container type (eg std::list<Element>)
// _Fn = function to call for each node
template <class _IC, class _OC, class _Fn> _Fn for_each(const _OC &list, _Fn
_Op)
{
    _OC::const_iterator itg = list.begin();
    _OC::const_iterator itge = list.end();

    for (; itg != itge; itg++)
    {
        const _IC *nested_list = *(*itg);

        _IC::const_iterator it = nested_list->begin();
        _IC::const_iterator ite = nested_list->end();
        std::for_each(it, ite, _Op);
    }

    return _Op;
}

-----Original Message-----
From: David Abrahams [mailto:abrahams_at_[hidden]]
Sent: 26 February 2001 22:46
To: boost_at_[hidden]
Subject: Re: [boost] does boost have iterators for nested std::list, or
similar ?
Importance: High

This looks like a good application for the iterator adaptor library, which
is available in the CVS archive and the next complete boost release.

-Dave

----- Original Message -----
From: "Craig Henderson" <craigh_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Monday, February 26, 2001 4:36 AM
Subject: [boost] does boost have iterators for nested std::list, or similar
?

> I am looking for a solution to the problem of iterating through a list of
a
> list using STL iterator technique, and wonder if boost provides any such
> functionality.
>
> for example, I have definitions such as
> class Element;
> typedef ElementList_t std::list<Element const *>;
> typedef GroupList_t std::list<ElementList const *>;
>
> and given a GroupList I need to iterator all the elements in a manner
along
> the lines of
>
> GroupList_t group;
> ElementList_t::const_iterator iter;
> for (iter = group.first_element(); iter!=group.last_element(); iter++)
> {
> Element const *pElement = *iter;
> ...
> }
>
> Now, obviously the iterator is going to have to be intelligent enough to
> iterate each ElementList in turn and move onto the next when appropriate.
>
> Before I begin development of such an iterator I thought it worth asking
the
> question of my peers ;)
>
> TIA
> Craig Henderson (new to boost)
>
>
>
>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>

Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk