std::copy_ifが標準に入っていないので自分で実装しよう!

http://d.hatena.ne.jp/parasporospa/20060129/1138487309
より。
http://d.hatena.ne.jp/a_little_bit/20050911#c
にて私も気づいた。あまりstd::copyやらstd::swapやらstd::for_eachやらをあまり使わない派だったりするので気づくのは遅かった^^;
ちなみにdKingyo Utility Toolkitのhelperには以下のソースが同梱されている。*1


/**
@auther http://d.hatena.ne.jp/a_little_bit/about
@brief stl algorithm copy_if()
@note
via
http://d.hatena.ne.jp/a_little_bit/20050911#c
http://www.geocities.jp/ky_webid/cpp/library/022.html
*/

#ifndef DKUTIL_HELPER_COPY_IF_HPP
#define DKUTIL_HELPER_COPY_IF_HPP



namespace dkutil{

template<class InputIterator, class OutputIterator, class Predicate>
inline OutputIterator copy_if(InputIterator first, InputIterator last,
OutputIterator result, Predicate pred)
{
for(; first != last; ++first)
if(pred(*first))
*result++ = *first;
return result;
}

}

namespace std{
///これ通るのか不明
using dkutil::copy_if;
}



#endif//end of include once


*1:まだリリースしてはいないが・・・^^;