#include #include #include #include #include #include "JLang/JPredicate.hh" #include "JLang/JComparison.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { class __A__ { public: __A__(const int a) { this->a = a; } int get() const { return a; } friend inline std::ostream& operator<<(std::ostream& out, const __A__& object) { return out << object.a; } int a; }; template void print(std::ostream& out, int debug, const char* title, T __begin, T __end) { using namespace std; using namespace JPP; if (debug >= debug_t) { out << title << endl; copy(__begin, __end, ostream_iterator(out, " ")); out << endl; } } } /** * \file * * Auxiliary program to test JLANG::JPredicate class and helper methods. * \author mdejong */ int main(int argc, char **argv) { using namespace std; using namespace JPP; int debug; try { JParser<> zap("Auxiliary program to test object selection methods."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } vector<__A__> buffer; buffer.push_back(__A__(3)); buffer.push_back(__A__(4)); buffer.push_back(__A__(2)); buffer.push_back(__A__(1)); buffer.push_back(__A__(5)); print(cout, debug, "data:", buffer.begin(), buffer.end()); int x = 3; { vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_predicate(&__A__::a, x)); DEBUG("has " << x << "? " << (p != buffer.end() ? "yes" : "no") << endl); ASSERT(p != buffer.end() && p->a == x); } { vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_predicate(&__A__::get, x)); DEBUG("has " << x << "? " << (p != buffer.end() ? "yes" : "no") << endl); ASSERT(p != buffer.end() && p->get() == x); } { vector<__A__>::iterator p = partition(buffer.begin(), buffer.end(), make_predicate(&__A__::a, x, JComparison::lt())); print(cout, debug, "selection:", buffer.begin(), p); for (vector<__A__>::iterator i = buffer.begin(); i != p; ++i) { ASSERT(i->a < x); } } return 0; }