Boost logo

Boost Users :

Subject: [Boost-users] Do "entire range" standard algorithms already exist
From: Kirk Korver (kkorver_at_[hidden])
Date: 2009-01-31 00:19:19


Group,

I recently found the boost::range library. It seems very useful.

An annoyance that I have with STL algorithms is that they are very
verbose. Most of the time I need to do something over the entire range.
I'm sure I'm not alone here.

 

At any rate, I can easily do this:

  

template< typename Range, typename Pred >
inline typename boost::range_iterator<Range>::type
find_if( Range& c, Pred pred )
{
    return std::find_if( boost::begin( c ), boost::end( c ), pred );
}

 

Which then allows me to do this:

 

void foo()

{

    typedef std::vector <int> V_INT;
    V_INT v;
    v.push_back(1);
    v.push_back(2);
    v.push_back(3);

 

    V_INT::iterator it = find_if(v, std::bind2nd(std::equal_to<int>(),
2));

}

 

Perfect. Exactly what I want. Search the entire vector, and I give it a
predicate.

 

I could easily create these functions for copy_if, erase_if, find_if,
and for_each.

 

My question:

Do I need to go ahead and create the tiny wrapper functions, or do they
already exist somewhere in Boost? If they exist already, I prefer to use
those.

 

Thank you in advance,

Kirk

 



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