#include #include #include #include using namespace std; #include using namespace GiNaC; class lst_prod { ex prod; public: lst_prod() : prod(ex(1)) { } lst_prod(const ex & init_) : prod(init_) { } void operator()(const ex & x) { cout << "We are called with argument " << x << endl; prod *= x; cout << "Current value of product is " << prod << endl; } ex result() const { return prod; } }; int main() { symbol a("a"), b("b"), c("c"); lst l; l = a, b, c; lst_prod test; for_each(l.begin(), l.end(), test); ex res = test.result(); cout << "---------------------"; cout << "List is " << l << endl; cout << "Product of it's elements is " << res << endl; return 0; } // vim:ts=2:sw=2