
DsSet::filter 함수를 사용하여 DsSet에 있는 요소 중 특정 조건을 만족하는 요소를 필터링하는 방법은 다음과 같습니다.
#hostingforum.kr
cpp
#include
int main() {
// DsSet 객체 생성
DsSet set;
// DsSet에 요소 추가
set.Add(10);
set.Add(20);
set.Add(30);
set.Add(40);
set.Add(50);
// DsSet::filter 함수를 사용하여 DsSet에 있는 요소 중 30 이상인 요소를 필터링
auto filteredSet = set.Filter([](int value) { return value >= 30; });
// 필터링된 요소 출력
for (auto value : filteredSet) {
printf("%d ", value);
}
printf("n");
return 0;
}
이 예제에서, DsSet::filter 함수는 DsSet에 있는 요소 중 30 이상인 요소를 필터링하고, 필터링된 요소를 새로운 DsSet 객체에 추가합니다. 필터링된 요소는 printf 함수를 사용하여 출력됩니다.
2025-07-13 19:23