Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-02-13 12:55:05

----- Original Message -----
From: "Douglas Gregor" <gregod_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 13, 2002 2:30 PM
Subject: Re: [boost] properties in C++

> 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
> > receive A*. Thus, 'value' cannot be default constructed and every
> > constructor for A requires a proper initialization of 'value'. This is
> > sort of complications that usually renders the technique not too
> > 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
> and constructor modifications). Of course, the property<> class would have
> understand what is going on here.
> Had I thought of this before, I'd be using properties in all my projects
> Doug
I see.
This certainly boils down the process of binding properties<->parent to a
single unique initialization.
However, I still don't like the approach. That is, I don't like any approach
that requires explicit binding, it's too error prone.

IMHO, the ONLY advantage of a 'property' in comparison with the good old:

    int const& foo() const { return m_foo ; }
    int & foo() { return m_foo ; }
    int m_foo ;

is that the user don't have to write the extra '()'.

I don't think that a property facility could add that much complexity just
to allow syntactic sugar.

Of course, I can be missing something and I'll be glad to know it.

Fernando Cacciola
Sierra s.r.l.

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