• Class / Function / Type

      std::
    • Header file

      <>
    • Other / All

    最終更新日時(UTC):
    が更新

    履歴 編集

    function template
    <algorithm>

    std::ranges::remove_copy

    namespace std::ranges {
      template <input_iterator I,
                sentinel_for<I> S,
                weakly_incrementable O,
                class T,
                class Proj = identity>
        requires indirectly_copyable<I, O> &&
                 indirect_binary_predicate<
                   ranges::equal_to,
                   projected<I, Proj>,
                   const T*
                 >
      constexpr remove_copy_result<I, O>
        remove_copy(I first,
                    S last,
                    O result,
                    const T& value,
                    Proj proj = {}); // (1) C++20
    
      template <input_range R,
                weakly_incrementable O,
                class T,
                class Proj = identity>
        requires indirectly_copyable<iterator_t<R>, O> &&
                 indirect_binary_predicate<
                   ranges::equal_to,
                   projected<iterator_t<R>, Proj>,
                   const T*
                 >
      constexpr remove_copy_result<borrowed_iterator_t<R>, O>
        remove_copy(R&& r,
                    O result,
                    const T& value,
                    Proj proj = {}); // (2) C++20
    }
    

    概要

    指定された要素を除け、その結果を出力の範囲へコピーする。

    事前条件

    • [first,last)[result,result + (last - first) は重なってはならない。

    効果

    [first,last) 内にあるイテレータ i について、invoke(proj, *i) == value でない要素を result へコピーする

    戻り値

    { .in = last, .out = result + (last - first) }

    計算量

    正確に last - first 回の比較を行う

    備考

    安定。

    #include <algorithm>
    #include <iostream>
    #include <vector>
    #include <iterator>
    
    int main() {
      std::vector<int> v = { 2,3,1,2,1 };
    
      // 1 を除去した結果を出力する
      std::ranges::remove_copy(v, std::ostream_iterator<int>(std::cout, ","), 1);
    }
    

    出力

    2,3,2,
    

    バージョン

    言語

    • C++20

    処理系

    参照