Boost logo

Boost :

From: Emily Winch (emily_at_[hidden])
Date: 2002-02-13 13:44:01


Geurt Vos said:

>Hi,
>I was wondering if there's interest in "properties
>for C++". Properties in the sense of: assigning
>to a data member will call a user-defined 'set'
>function, reading from the data member will call
>a user-defined 'get' function.

[ snipped example implementation ]

An alternative compile-time implementation for properties
is the associative_list which I am really, really going to
let out of the door pretty soon. It potentially lets you have
a group of properties that default to "direct" access, but
that allow specialisation for more complex access. You
end up with syntax like

x.set<Name>("Fred");

instead of

x.name = "Fred";

but I think that's an advantage: it makes it more clear that
there is a function call involved.

Disadvantages include larger object size due to alignment
issues (I think it might be possible to fix this) and some
construction nastiness. (Default construction of the properties
is all-or-none; objects get copied a lot during construction.
I don't know how to fix either of these).

There's a reasonably detailed description of the whole thing
here: www.oonumerics.org/tmpw01/winch.pdf

Emily.


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