Effective STL 第36条
2022-10-18 本文已影响0人
懒生活
copy_if的实现
实际上copy_if在C++11已经支持了. 在这本书出版的时候,还不支持.所以作者提供了copy_if实现. 现在编程已经不需要了.这里就当了解下具体实现.
template<typename InputIterator, typename OutputIterator, typename Predicate>
OutputIterator my_copy_if(InputIterator begin, InputIterator end, OutputIterator destBegin, Predicate p)
{
while (begin != end)
{
if (p(*begin))
{
*destBegin++ = *begin;
++begin;
}
return destBegin;
}
}