#include <iostream>
#include <algorithm>
using namespace std;
bool myfn(int i, int j) { return i<j; }
int main () {
int myints[] = {3,7,2,5,6,4,9};
// using function myfn as comp:
cout << "The smallest element is " << *min_element(myints,myints+7,myfn) << endl;
cout << "The largest element is " << *max_element(myints,myints+7,myfn) << endl;
return 0;
}
考虑到上面的代码,如果我们通过myfn
或&myfn
到 有什么区别min_element
吗?当我们试图传递一个函子时,哪一个是更标准的方式?