Boost logo

Boost Users :

From: chun ping wang (cablepuff_at_[hidden])
Date: 2007-11-30 13:07:19


hey i am curious on the actual code you written. Cause i want to know if
doing that is faster than copying an item to a container and like iterate
over that.

template
    <
       class T, class U,
       template <typename ELEM, typename = std::allocator<ELEM> >
       class CONT
>
CONT<T> getKeys(const boost::unordered_map<T, U>& data)
{
    CONT<T> retCont;
    typedef typename boost::unordered_map<T, U>::value_type value_type;
    BOOST_FOREACH(value_type val, data)
    {
        retCont.push_back(val.first);
    }
    return retCont;
}

Note i am using keys instead of value but concept is the same.
On Nov 30, 2007 1:59 AM, John Kiopela <john.kiopela_at_[hidden]> wrote:

> Thanks a lot both. Transform Iterator did the trick.
>
> Kind regards,
>
> John
>
> On Nov 29, 2007 9:04 PM, Niels Aan de Brugh <niels_at_[hidden]> wrote:
>
> > On 2007-11-29, John Kiopela <john.kiopela_at_[hidden]> wrote:
> > >
> > > I have been browsing through the docs, but I couldn't find anything
> > useful.
> > > Does Boost have a std::map<K, V>::iterator adaptor which iterates over
> > the
> > > values of the map only.
> >
> > What about using a boost::transform_iterator<>? Docs at:
> >
> > http://boost.org/libs/iterator/doc/transform_iterator.html
> >
> > You'd have to supply it with a function object that returns the 'second'
> > member variable of the pair, e.g.
> >
> > struct get_pair_value
> > {
> > template< typename K, typename V >
> > V operator()( std::pair< K, V > const& pr )
> > { return pr.second; }
> > };
> >
> > Or you could use Boost.Lambda.
> >
> > N.
> >
> >
> > _______________________________________________
> > Boost-users mailing list
> > Boost-users_at_[hidden]
> > http://lists.boost.org/mailman/listinfo.cgi/boost-users
> >
>
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net