find_if_not
template <class InputIterator, class Predicate> bool find_if_not(InputIterator first, InputIterator last, Predicate pred);
「~であるものを探す」find_ifがあるなら「~でないものを探す」find_if_notもあっていいよね。
……つづき
ia5::iterator iter;
// find_if_not
function<bool(int)> divisor_of_12 = [](int n) { return 12 % n == 0; };
iter = find_if_not(c.begin(), c.end(), divisor_of_12); // 12の約数じゃないもの
assert( iter != c.end() && *iter == 5 );
// 従来こう書いてた
iter = find_if(c.begin(), c.end(), not1(divisor_of_12));
assert( iter != c.end() && *iter == 5 );
……つづく
copy_if, copy_n
template <class InputIterator, class OutputIterator, class Predicate>
OutputIterator copy_if(InputIterator first, InputIterator last,
OutputIterator result, Predicate pred);
template <class InputIterator, class Size, class OutputIterator>
OutputIterator copy_n(InputIterator first, Size n, OutputIterator result);
copy_ifは条件を満たすものだけをコピーします。今までなかったのが不思議です。条件を満たすものをコピー対象としないremove_copy_ifはあったのに。
コピー範囲を最初の要素を指すイテレータとコピー個数で指定するcopy_nも追加されました。
……つづき // copy_if vector<int> iv; copy_if(c.begin(), c.end(), back_inserter(iv), u_even); // 偶数のみをvにコピー assert( iv.size() == 3 ); iv.clear(); // 従来こう書いてた remove_copy_if(c.begin(), c.end(), back_inserter(iv), not1(u_even)); assert( iv.size() == 3 ); // copy_n copy_n(c.begin(), 3, iv.begin()); assert( accumulate(iv.begin(), iv.end(), 0) == 9 ); // 従来こう書いてた iter = c.begin(); advance(iter,3); copy(c.begin(), iter, iv.begin()); assert( accumulate(iv.begin(),iv.end(),0) == 9 ); ……つづく
