美文网首页
Effective STL 第36条

Effective STL 第36条

作者: 懒生活 | 来源:发表于2022-10-18 23:19 被阅读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;
        }
    }
    

    相关文章

      网友评论

          本文标题:Effective STL 第36条

          本文链接:https://www.haomeiwen.com/subject/ubnszrtx.html