다음은 컴파일하지 않은 C++로 작성된 코드 조각입니다. 이유는 not1()을 사용하여 람다 함수의 결과를 반대로 변경하려고하기 때문입니다. 사람이 접근 방식의람다 함수 결과를 무효화하는 방법
#include <iostream> // std::cout
using namespace std;
#include <functional> // std::not1
#include <algorithm> // std::count_if
#include <vector>
int main() {
vector<int> sv = {3, 5, 10,12 };
vector<int> v = { 1,2,3,4,5,6,7,8,9,10,11,12,13,14,15 };
auto validSelection = [&](auto& e) {
auto isSelected = [&] (auto& sve) {
return e == sve;
};
return find_if(sv.begin(), sv.end(), isSelected) != sv.end();
};
stable_partition(v.begin(), next(v.begin(),8) , not1(validSelection));
for (int n : v) {
std::cout << n << ' ';
}
std::cout << '\n';
return 0;
}
나는 "컴파일하지 않는다"는 오류 메시지가 아니라는 것을 꽤 잘 알고 있습니다. –
왜'notl'을하기 위해 람다 (lambda)를 사용하지 않는가? (적어도 나에게는) 분명하다. –
@appleapple 특히이 코드가 이미 필요하지 않은 곳에 람다를 사용할 때 – Slava