Do "entire range" standard algorithms already exist

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

Content-class: urn:content-classes:message Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C98363.78536B2F"
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.
Some exist in the sandbox. Look in sandbox/boost/algorithm. -- -- Marshall Marshall Clow Idio Software mailto:marshall@idio.com It is by caffeine alone I set my mind in motion. It is by the beans of Java that thoughts acquire speed, the hands acquire shaking, the shaking becomes a warning. It is by caffeine alone I set my mind in motion.

On Sat, Jan 31, 2009 at 00:19, Kirk Korver
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.
It looks like RangeEx (a proposed replacement for boost.range) includes that: http://www.nabble.com/-RangeEx--Range---RangeEx-td19454585.html

Phoenix has complete wrapper for std algorithm using range. It uses a functional programming style so the syntax is a bit different but not much. In your case the code would look like this :
V_INT::iterator it = boost::phoenix::find_if(_1, std::bind2nd(std::equal_to<int>(), 2))(v);
you can read phoenix documentation at BOOST_ROOT/libs/spirit/phoenix/index.html
--- Pada Jum, 30/1/09, Kirk Korver
participants (4)
-
Kamil Zubair
-
Kirk Korver
-
Marshall Clow
-
Scott McMurray