From: Henrik Ravn (henrik_at_[hidden])
Date: 2001-11-06 03:22:55


 
> That what I thought, but I seems to work on many compilers. ;-)(.
>
> Gennadiy.
>
> P.S. Does anybody know conformable alternative?

I have looked at it for a while now, and I can't really come up with
anything elegant.

I have found 2 workarounds that both have drawbacks:

1. define macros that expands with a friend declaration
Something like this:
#define READONLY_PROPERTY( type, name, owner ) \
class roprop_##name : public readonly_property< type > \
{ friend class owner; public: ro_prop##name(readonly_property< type>
::param_type v)\
: readonly_property< type >(v) {} } name

... and something similar for writeonly_property. So, instead of
struct X { readonly_property<int,X> n; };
You would have to go:
Struct X { READONLY_PROPERTY(int, n, X ); };

This would be just as 'safe' as the original code, but quite ugly.

2. define a friend accessor class outside the ro/wo classes
class property_owner {
protected:
  template<class Property> typename Property::reference
get_property_reference(Property& prop) { return prop.get_reference();
}
};

template<typename T>
class readonly_property {
  friend property_owner;
  // etc...
};

This is less convenient than the macro workaround, because the owner
class would have to derive from property_owner. Is is less ugly than the
macro workaround, but also less safe, in that any class that derives
from property_owner would be able to access any property of any class.

Any other ideas? Comments?

Be well
Henrik