Boost logo

Boost Users :

From: David Abrahams (dave_at_[hidden])
Date: 2007-03-29 12:26:46


on Thu Mar 29 2007, "Ovanes Markarian" <om_boost-AT-keywallet.com> wrote:

> On Thu, March 29, 2007 09:28, Joaquín Mª López Muñoz wrote:
> [snip ...]
>>
>> This works, but it is quite inefficient, as mpl::find, which computes
>> in linear time, is called for every element of Seq. The same thing
>> can be done in one pass through the sequence as follows:
>>
>> template<typename Seq,typename T>
>> struct eraseVal2:mpl::copy_if<Seq,mpl::not_<boost::is_same<mpl::_,T> > >
>> {};
>>
>> Please find attached a compilable snippet showing both algorithms
>> at work.
>>
>> HTH,
>>
>> Joaquín M López Muñoz
>> Telefónica, Investigación y Desarrollo
>
> Another approach would be to use the filter_view, without copying the elements.

Yeah, why struggle? This problem looks tailor-made for filter_view.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com
Don't Miss BoostCon 2007! ==> http://www.boostcon.com

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