Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-02-13 15:20:44


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

> On Wednesday 13 February 2002 12:55 pm, you wrote:
> > 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.
>
> There's no reason that properties be restricted to 'just' being syntactic
> sugar (note: in my world, syntax is _everything_, so that's enough of an
> argument for me already).
>
>
I agree that syntax is __everthing__; is just that I think that not
everything is syntax !-)
I mean, I can decide that 'foo' ought to be 'foo', not, 'bar' or 'a'; but
I'm not sure if foo()/foo are really different in the context we're
discussing.

> Since every property will know the address of the object containing it,
> properties can also be used for setting values at run-time and for
> reflection. Let's say we can do this (some abbreviations in the code):
>
> class Window : public runtime_properties {
> public:
> union {
> Window* self;
> property< read<&Window::get_top>, write<&Window::set_top> > top;
> property< read<&Window::get_left>, write<&Window::set_left> > left;
> property< read<&Window::get_width>, write<&Window::set_width> > width;
> property< read<&Window::get_height>, write<&Window::set_height> >
height;
> }
>
> Window() :
> self(this), top("Top", 0), left("Left", 0),
> width("Width", 100), height("Height", 100)
> {
> }
> };
>
> The intention here is that the properties can register themselves with the
> "runtime_properties" base class of the Window class. They tell the
> runtime_properties base class:
> 1) Their human-readable names
> 2) Their default values (optional)
> 3) How to read and/or write their values
>
> Properties such as this have been made language features before (see
Delphi
> or C++ Builder), and the degree to which one can interact with a component
> via its properties is wonderful.
>
OK, I now see your point:

With

int& foo() ;

there's no way for the holder to really tell if the value of foo changed (or
was initialzed, for that matter); while with

void set_foo( int ) ;

it can.

This is useful functionality, and properties hide the ugly 'set_xxx()'
syntax.

Good point!

Fernando Cacciola
Sierra s.r.l.
fcacciola_at_[hidden]
www.gosierra.com

> Did I mention that the syntax is nicer? :)
>
> Doug
>
> Info: http://www.boost.org Send unsubscribe requests to:
<mailto:boost-unsubscribe_at_[hidden]>
>
> Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
>
>
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk