Boost logo

Boost Users :

Subject: [Boost-users] Bls: Do "entire range" standard algorithms already exist
From: Kamil Zubair (kamilzubair_at_[hidden])
Date: 2009-02-01 00:09:56


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 <kkorver_at_[hidden]> menulis:
Dari: Kirk Korver <kkorver_at_[hidden]>
Topik: [Boost-users] Do "entire range" standard algorithms already exist
Kepada: boost-users_at_[hidden]
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_at_[hidden]
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/



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