Topic: std::copy_if - most likely canidate?
Author: orawnzva.cengg@irevmba.arg ("Benjamin Pratt")
Date: Sat, 8 Feb 2003 02:12:23 +0000 (UTC) Raw View
I know I can create my own copy_if to supplement the STL, however, is there
a typically used copy_if implementation that will most likely be added to
the next standard, so if I use that implementation, my code will have the
greatest chance of being compatable with std::copy_if?
Thanks,
Ben
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dietmar_kuehl@yahoo.com (Dietmar Kuehl)
Date: Sat, 8 Feb 2003 05:37:35 +0000 (UTC) Raw View
Benjamin Pratt wrote:
> I know I can create my own copy_if to supplement the STL, however, is
> there a typically used copy_if implementation that will most likely be
> added to the next standard, so if I use that implementation, my code will
> have the greatest chance of being compatable with std::copy_if?
Well, I'd guess it would be something like this:
template <typename InIt, typename OutIt, typename UnaryPred>
OutIt
copy_if(InIt begin, InIt end, OutIt to, UnaryPred pred)
{
return remove_copy_if(begin, end, to, not1(pred));
}
I have no clue whether it will be added to the standard, tough...
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: abarbati@iaanus.com (Alberto Barbati)
Date: Mon, 10 Feb 2003 22:53:11 +0000 (UTC) Raw View
Dietmar Kuehl wrote:
> Benjamin Pratt wrote:
>
>>I know I can create my own copy_if to supplement the STL, however, is
>>there a typically used copy_if implementation that will most likely be
>>added to the next standard, so if I use that implementation, my code will
>>have the greatest chance of being compatable with std::copy_if?
>
>
> Well, I'd guess it would be something like this:
>
> template <typename InIt, typename OutIt, typename UnaryPred>
> OutIt
> copy_if(InIt begin, InIt end, OutIt to, UnaryPred pred)
> {
> return remove_copy_if(begin, end, to, not1(pred));
> }
not1 requires UnaryPred to be adaptable. I'd guess the only way of
implementing copy_if for the general case is to duplicate the
implementation of remove_copy_if removing a "!" somewhere in it.
> I have no clue whether it will be added to the standard, tough...
I wish it will. I still don't see the reason why it has been dropped
from the standard in the first place.
Alberto Barbati
-----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
-----== Over 80,000 Newsgroups - 16 Different Servers! =-----
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]
Author: dietmar_kuehl@yahoo.com (Dietmar Kuehl)
Date: Tue, 11 Feb 2003 17:08:54 +0000 (UTC) Raw View
abarbati@iaanus.com (Alberto Barbati) wrote:
> Dietmar Kuehl wrote:
> > template <typename InIt, typename OutIt, typename UnaryPred>
> > OutIt
> > copy_if(InIt begin, InIt end, OutIt to, UnaryPred pred)
> > {
> > return remove_copy_if(begin, end, to, not1(pred));
> > }
> not1 requires UnaryPred to be adaptable. I'd guess the only way of
> implementing copy_if for the general case is to duplicate the
> implementation of remove_copy_if removing a "!" somewhere in it.
Duplicating the implementation o an algorithm for something like this would
kind of defeat the purpose of the STL. On the other hand, you are right:
'std::not1()' indeed imposes an additional requirement on the predicate.
However, the following 'unary_negate' template does not have this problem:
template <typename Predicate>
struct unary_negate {
unary_negate(Predicate predicate): m_predicate(predicate) {}
template <typename T>
bool operator()(T const& object) const { return !m_predicate(object); }
Predicate m_predicate;
}:
--
<mailto:dietmar_kuehl@yahoo.com> <http://www.dietmar-kuehl.de/>
Phaidros eaSE - Easy Software Engineering: <http://www.phaidros.com/>
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.jamesd.demon.co.uk/csc/faq.html ]