Hi, Studying STL I have tried to negate a functor with not2 but encontered problems. Here is the example:
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
using namespace std;
struct mystruct : binary_function<int,int,bool> {
bool operator() (int i,int j) { return i<j; }
};
template <class T>
class generatore
{
public:
generatore (T start = 0, T stp = 1) : current(start), step(stp)
{ }
T operator() () { return current+=step; }
private:
T current;
T step;
};
int main () {
vector<int> first(10);
generate(first.begin(), first.end(), generatore<int>(10,10) );
cout << "Smallest element " << *min_element(first.begin(), first.end(),mystruct() ) << endl;
cout << "Smallest element: " << *max_element(first.begin(), first.end(),not2(mystruct())) << endl;
}
Last line of code wil not compile using g++. Probably a stupid error but where ?