기본 콘텐츠로 건너뛰기

라벨이 predicatie인 게시물 표시

std::list::remove_if(), std::list::sort()

link  http://hyunity3d.tistory.com/244?category=527936 코드 돌려보고 c++11 형태로 문법오류 수정해서 동작 처리 #include <iostream> #include <list> #include <functional>   // std::unary_function // 20 이상 30 미만이면 true template <typename T> class Is_Over20_Under30 : public std::unary_function<T, bool> // argument type - T, result type - bool { public: bool operator( ) (T& val) { return (val >= 20 && val < 30); } }; // 함수 객체 정의 template <typename T> struct COMPARE_ITEM { bool operator()(const T l, const T r) const { // 정렬 시에는 올림 차순으로된다. 내림 차순으로 하고 싶으면 < 에서 > 로 변경하면 된다. return l < r; } }; int test8() { std::list< int > list1; list1.push_back(10); list1.push_back(20); list1.push_back(25); list1.push_back(30); list1.push_back(34); std::cout << std::endl << "remove_if  테스트 1 - 사용자가 정의한 조건에 의해 삭제" << std::endl; // 20 이상 30 미만은 삭제한다. list1.remove_if(I...