#include #include #include #include #include #define COMMENTED_OUT_NODE typedef std::vector::size_type size_type; struct Node { Node() : conc_(0) {} double conc() const { return conc_; } void set_conc(double val) { conc_ = val; } private: double conc_; }; struct FEM { FEM(std::vector const & nodes) : nodes_(nodes) {} size_type nnodes() const { return nodes_.size(); } Node & node(size_type i) { return nodes_[i]; } #ifndef COMMENTED_OUT_NODE Node const & node(size_type i) const { return nodes_[i]; } #endif private: std::vector nodes_; }; #ifdef COMMENTED_OUT_NODE struct nodeGetter { nodeGetter(FEM & fem) : fem_(fem) {} Node & operator()(size_type i) const { return fem_.node(i); } private: FEM & fem_; }; #endif int main() { std::vector nodes(10); FEM fem(nodes); size_type i = 5; double const val = 14; #ifdef COMMENTED_OUT_NODE nodeGetter ng(fem); boost::function2 set_value = boost::bind(&Node::set_conc, boost::bind(&nodeGetter::operator(), ng, _1), _2); #else boost::function2 set_value = boost::bind(&Node::set_conc, boost::bind(&FEM::node, boost::ref(fem), _1), _2); #endif set_value(i, val); std::cout << fem.node(i).conc() << std::endl; return 0; }