#include #include #include #include #include #include "JLang/JFind_if.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; }; class JPredicate_t { public: JPredicate_t(const int value) : value(value) {} bool operator()(const int value) const { return this->value == value; } int value; }; 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()); JPredicate_t predicate(3); { vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_find_if(&__A__::a, predicate)); DEBUG("has " << predicate.value << "? " << (p != buffer.end() ? "yes" : "no") << endl); ASSERT(p != buffer.end() && p->a == predicate.value); } { vector<__A__>::const_iterator p = find_if(buffer.begin(), buffer.end(), make_find_if(&__A__::get, predicate)); DEBUG("has " << predicate.value << "? " << (p != buffer.end() ? "yes" : "no") << endl); ASSERT(p != buffer.end() && p->get() == predicate.value); } return 0; }