#include #include #include #include class X { public: std::string text() { return std::string("hello world!"); } }; class Y { public: int value() { return 5; } }; class Z { public: bool isEnabled() { return true; } }; // [...] // There will be hundreds of classes like X, Y and Z, only quite more complex class Proxy { public: boost::any field( class_name, instance, method ) { // FIXME What should be the signature of this method? boost::function< boost::any (class_name*) > fun; fun=method; return boost::any( fun( &instance ) ); } }; int main() { // { // boost::function f; // f=&X::text; // // X x; // std::cout << "x.text() is " << x.text() << std::endl; // std::cout << "f(&x) is " << boost::any_cast(f(&x)) << std::endl; // } X x; Proxy px; std::string the_value_of_x = boost::any_cast( px.field(X, x, X::text ) ); // { // boost::function f; // f=&Y::value; // // Y y; // std::cout << "y.value() is " << y.value() << std::endl; // std::cout << "f(&y) is " << boost::any_cast(f(&y)) << std::endl; // } Y Y; Proxy py; std::string the_value_of_y = boost::any_cast( py.field(Y, y, Y::value ) ); // { // boost::function f; // f=&Z::isEnabled; // // Z z; // std::cout << "z.isEnabled() is " << z.isEnabled() << std::endl; // std::cout << "f(&z) is " << boost::any_cast(f(&z)) << std::endl; // }*/ Z z; Proxy pz; std::string the_value_of_z = boost::any_cast( pz.field(Z, z, Z::isEnabledtext ) ); return 0; }