Boost logo

Boost :

From: Stefan Strasser (sstrasser_at_[hidden])
Date: 2005-04-09 18:15:51


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; }

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; \
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{
   property &operator=(T const &t){
     unsigned int temp=(unsigned int)this;
     ClassT *this_=(ClassT *)temp;
     return *this;


Stefan Strasser

Boost list run by bdawes at, gregod at, cpdaniel at, john at