// 算术类函数对象 // 算术类函数对象 #include #include #include using namespace std; // template void print(typename set::const_iterator start, typename set::const_iterator end, plus pl, int m) { for (; start != end; start++) { cout << pl(*start, m) << " "; } cout << endl; } void print(typename set::const_iterator start, typename set::const_iterator end, multiplies mul, int m) { for (; start != end; start++) { cout << mul(*start, m) << " "; } cout << endl; } int main() { int m[] = {1, 2, 3, 4, 8, 5, 1, 2}; // set 会自动过滤重复,并排序 set s(m, m + sizeof(m) / sizeof(m[0])); print(s.begin(), s.end(), plus(), 1); print(s.begin(), s.end(), multiplies(), 3); return 0; }