#include #include using namespace GiNaC; using namespace std; struct mypair_s { ex left, right; mypair_s() {} mypair_s(const ex & l, const ex & r) : left(l), right(r) {} }; inline bool operator==(const mypair_s & lhs, const mypair_s & rhs) { return lhs.left.is_equal(rhs.left) && lhs.right.is_equal(rhs.right); } inline bool operator<(const mypair_s & lhs, const mypair_s & rhs) { return lhs.left.compare(rhs.left) < 0 ? true : lhs.right.compare(rhs.right) < 0; } typedef structure mypair; inline ex make_mypair(const ex & l, const ex & r) { return mypair(mypair_s(l, r)); } namespace GiNaC { template <> void mypair::print(const print_context & c, unsigned level) const { const mypair_s & p = get_struct(); c.s << "{" << p.left << "," << p.right << "}"; } template <> size_t mypair::nops() const { return 2; } template <> ex mypair::op(size_t i) const { switch(i) { case 0: return get_struct().left; case 1: return get_struct().right; default: throw std::range_error("mypair::op(): no such operand"); } } template <> ex &mypair::let_op(size_t i) { ensure_if_modifiable(); switch(i) { case 0: return get_struct().left; case 1: return get_struct().right; default: throw std::range_error("mypair::let_op(): no such operand"); } } } // namespace GiNaC int main(int argc, char** argv) { symbol a("a"), b("b"), c("c"); ex e = make_mypair(make_mypair(a,c),b); cout << e.subs(make_mypair(a,c) == b, subs_options::no_pattern) << endl; return 0; }