| Jon Stewart on Mon, 22 Mar 2004 20:14:49 -0600 (CST) |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
| Re: [ALACPP] copy_if? |
> Okay, new wrinkle here. At lunch, John pointed me to:
>
> std::replace_copy_if()
>
> as the hackish-but-workable solution to my copy_if function.
> So, I quickly hacked this up:
>
> template<typename InputIterator, typename OutputIterator,
> typename Predicate>
> inline OutputIterator copy_if(InputIterator first, InputIterator last,
> OutputIterator result, Predicate pred)
> {
> return std::remove_copy_if(first, last, result, boost::not1(pred));
> }
>
> Here's the funny thing. This works if I invoke it with:
>
> copy_if(temp.begin(), temp.end(), ostream_iterator<string>(cout, "\n"),
> sillyUnaryFunction);
>
> But it fails with:
>
> copy_if(temp.begin(), temp.end(), ostream_iterator<string>(cout, "\n"),
> boost:bind(sillyBinaryFunction, _1 value));
>
> Seems like a classic case of boost's funky type theory killing me. I
> have yet to figure out the exact nature of the problem. It's worth
> noting that my original implementation handed both cases with aplomb.
Probably a boost::bind usage error (not uncommon). Do you have a comma
after "_1" in your source?
> Not sure if std::remove_copy_if() is a net win really.
Yeah, copy_if is so nice and simple that it doesn't benefit too much from
code reuse.
Jon
--
Jon Stewart Advanced Los Angeles C++
stew1@xxxxxxxxxxx http://www.alacpp.org
_______________________________________________
alacpp mailing list
alacpp@xxxxxxxxxxx
http://lists.ellipsis.cx/mailman/listinfo/alacpp