qfedu-cpp-level/day10/stl_algorithm_demo/f2.cpp

26 lines
461 B
C++
Raw Permalink Normal View History

2023-08-14 17:20:39 +08:00
#include <iostream>
#include <set>
#include <algorithm>
using namespace std;
class PrintGt5Adapter : public binary_function<int, int, void>
{
public:
void operator()(const int &n1, const int &n2) const
{
if (n1 > n2)
cout << n1 << " ";
}
};
int main()
{
int m[] = {1, 2, 3, 4, 8, 5, 1, 2};
set<int> s(m, m + sizeof(m) / sizeof(m[0]));
for_each(s.begin(), s.end(), bind2nd(PrintGt5Adapter(), 2));
return 0;
}