[C++] copy_if
Updated:
개요
- 범위내의 요소 중 조건을 만족하는 요소를 복사
예제
- 코드
#include <algorithm> #include <iostream> #include <vector> using namespace std; int main() { vector<int> v1{1, 2, 3, 4, 5}; for (const auto &iter : v1) { cout << iter << endl; } cout << "------" << endl; vector<int> v2; copy_if(v1.begin(), v1.end(), back_inserter(v2), [](int i) { return i >= 3; }); for (const auto &iter : v2) { cout << iter << endl; } return 0; }
- 실행 결과
1 2 3 4 5 ------ 3 4 5