GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • cpprefjp - C++日本語リファレンス
  • GitHub Project

This view

  • Original page
  • New address

GeezerVison is showing cpprefjp.github.io — std::remove_copy_if - cpprefjp C++日本語リファレンス

  1. リファレンス
  2. algorithm
  3. remove_copy_if

最終更新日時: 2026年08月25日 12時11分17秒 (JST)
Akira Takahashi が更新

履歴 編集

function template
<algorithm>

std::remove_copy_if

namespace std {
  template <class InputIterator, class OutputIterator, class Predicate>
  OutputIterator
    remove_copy_if(InputIterator first,
                   InputIterator last,
                   OutputIterator result,
                   Predicate pred);         // (1) C++98

  template <class InputIterator, class OutputIterator, class Predicate>
  constexpr OutputIterator
    remove_copy_if(InputIterator first,
                   InputIterator last,
                   OutputIterator result,
                   Predicate pred);         // (1) C++20

  template <class ExecutionPolicy, class ForwardIterator1, class ForwardIterator2,
            class Predicate>
  ForwardIterator2
    remove_copy_if(ExecutionPolicy&& exec,
                   ForwardIterator1 first,
                   ForwardIterator1 last,
                   ForwardIterator2 result,
                   Predicate pred);         // (2) C++17
}

概要

イテレータ範囲[first, last)から条件を満たす要素を除け、その結果を出力の範囲へコピーする。

テンプレートパラメータ制約

  • *result = *first という式が有効であること

事前条件

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

効果

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

戻り値

実行結果の範囲の終端を返す

計算量

正確に last - first 回の述語の適用を行う

備考

安定

例

#include <algorithm>
#include <iostream>
#include <vector>
#include <iterator>

int main() {
  std::vector<int> v = { 2,3,1,2,1 };

  // 奇数を除去した結果を出力する
  std::remove_copy_if(v.begin(), v.end(),
    std::ostream_iterator<int>(std::cout, ","),
    [](int x) { return x%2 != 0; });
}

出力

2,2,

実装例

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

関連項目

  • ranges::remove_copy_if

参照

  • P0202R3 Add Constexpr Modifiers to Functions in <algorithm> and <utility> Headers
  • P0467R2 Iterator Concerns for Parallel Algorithms
You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.