|
Boost : |
From: Douglas Gregor (gregod_at_[hidden])
Date: 2002-02-13 12:30:33
On Wednesday 13 February 2002 11:01 am, you wrote:
> My point is that there is NO WAY to store &A inside 'value' at compile
> time. You can store &A::foo, but without &A this still requires runtime
> support.
>
> The typical solutions that I'm aware of require the property constructor to
> receive A*. Thus, 'value' cannot be default constructed and every
> constructor for A requires a proper initialization of 'value'. This is the
> sort of complications that usually renders the technique not too friendly
> and ultimately discarded.
Here's a hack that might help:
class MyClass {
public:
union {
MyClass* self;
property<read<&MyClass::get_foo>, write<&MyClass::set_foo> > foo;
property<read<&MyClass::get_bar>, write<&MyClass::set_bar> > bar;
}
};
This allows properties to be used with only constant overhead (in object size
and constructor modifications). Of course, the property<> class would have to
understand what is going on here.
Had I thought of this before, I'd be using properties in all my projects :)
Doug
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk