Re: [Boost-users] boost::array < pair<>... > iterator adaptor
AMDG Hicham Mouline wrote:
I have a boost::array< pair
, maxsize > object, and I wish to iterate over the list of type1 elements, and the list of type2 elements... I gather I then need an iterator adaptor based on array's iterator and const_iterators... How may I write such a thing?
I then can pass around iterators to type1 and type2 separately.
transform_iterator might be useful. I don't know off the top of my head whether there is a more specialized iterator adaptor in Boost somewhere. Great, this worked beautifully
struct FirstElem : public std::unary_function< pair<>, double > { double operator()( const pair<>& p ) { return p.first; } }; typedef boost::transform_iterator< FirstElem, IterType > FirstElemIterType; FirstElemIterType feit ( container.begin() ); I can then pass feit around. Now, under normal assumptions, accessing first elements through feit should be as fast as direct access by manual loop.... inline calls should be optimized away? Thanks,
On Thu, Apr 2, 2009 at 11:30, Hicham Mouline
Now, under normal assumptions, accessing first elements through feit should be as fast as direct access by manual loop.... inline calls should be optimized away?
Yes. Though it looks like transform_iterator doesn't yet EBO the functor, so you'll pay a bit of a space penalty, but in most cases it should be inconsequential.
participants (2)
-
Hicham Mouline
-
Scott McMurray