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 menulis:
Dari: Kirk Korver
Topik: [Boost-users] Do "entire range" standard algorithms already exist
Kepada: boost-users@lists.boost.org
Tanggal: Jumat, 30 Januari, 2009, 11:19 PM
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 mailing list
Boost-users@lists.boost.org
http://lists.boost.org/mailman/listinfo.cgi/boost-users
___________________________________________________________________________
Dapatkan nama yang Anda sukai!
Sekarang Anda dapat memiliki email di @ymail.com dan @rocketmail.com.
http://mail.promotions.yahoo.com/newdomains/id/