
Hi, I'd like to know if there is interest in developing a small library for inclusion in boost to emulate properties, something like: struct A{ void SetVar(int a){ cerr << "set " << a << endl; } int GetVar() const{ cerr << "get" << endl; return 0; } BOOST_PROPERTY(A,int,Var,SetVar,GetVar); }; A a; a.Var=3; //calls SetVar here's a proof-of-concept implementation which works with gcc 3.4 and intel cc: #define BOOST_PROPERTY(ClassT,T,name,setter,getter) \ struct _##name##_offset; \ property<T,ClassT,_##name##_offset,&ClassT::setter,&ClassT::getter> name; \ struct _##name##_offset{ \ size_t operator()() const{ \ return (size_t) &((ClassT *)0)->name; \ } \ } template<typename T,typename ClassT,typename offset,void (ClassT::*setter)(T),T (ClassT::*getter)() const> class property{ public: property &operator=(T const &t){ unsigned int temp=(unsigned int)this; temp-=offset()(); ClassT *this_=(ClassT *)temp; (this_->*setter)(t); return *this; } }; Regards, -- Stefan Strasser

Stefan Strasser wrote:
Hi,
I'd like to know if there is interest in developing a small library for inclusion in boost to emulate properties, something like:
struct A{ void SetVar(int a){ cerr << "set " << a << endl; } int GetVar() const{ cerr << "get" << endl; return 0; } BOOST_PROPERTY(A,int,Var,SetVar,GetVar); };
A a; a.Var=3; //calls SetVar
You might like to look at this thread: http://lists.boost.org/MailArchives/boost/msg74302.php Jonathan

Jonathan Turkanis schrieb:
Stefan Strasser wrote:
Hi,
I'd like to know if there is interest in developing a small library for inclusion in boost to emulate properties, something like:
struct A{ void SetVar(int a){ cerr << "set " << a << endl; } int GetVar() const{ cerr << "get" << endl; return 0; } BOOST_PROPERTY(A,int,Var,SetVar,GetVar); };
A a; a.Var=3; //calls SetVar
You might like to look at this thread: http://lists.boost.org/MailArchives/boost/msg74302.php
thanks! though I think an implementation like the one described in N1615 is impractical to use, because, besides the overhead of the implementation pointer, you need to explicitly construct each property. which isn't required, with the drawback of using a macro to declare properties. however, where can you find it? it isn't in the sandbox anymore. -- Stefan Strasser

Stefan Strasser wrote:
Jonathan Turkanis schrieb:
Stefan Strasser wrote:
Hi,
I'd like to know if there is interest in developing a small library for inclusion in boost to emulate properties, something like:
You might like to look at this thread: http://lists.boost.org/MailArchives/boost/msg74302.php
thanks! though I think an implementation like the one described in N1615 is impractical to use, because, besides the overhead of the implementation pointer, you need to explicitly construct each property. which isn't required, with the drawback of using a macro to declare properties.
however, where can you find it? it isn't in the sandbox anymore.
This link worked for me: http://uk.geocities.com/msclrhd/boost/property.zip Jonathan
participants (2)
-
Jonathan Turkanis
-
Stefan Strasser