Boost logo

Boost :

From: Fernando Cacciola (fcacciola_at_[hidden])
Date: 2002-02-13 09:14:28


----- Original Message -----
From: "Geurt Vos" <G.Vos_at_[hidden]>
To: <boost_at_[hidden]>
Sent: Wednesday, February 13, 2002 6:01 AM
Subject: [boost] properties in C++

> 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.
>
> Example:
>
> class A {
> private:
> void set_it(int);
> int get_it() const;
> public:
> [...] value;
> };
>
> A a;
> a.value = 100;
> -> a.set_it(100);
> int i = a.value
> -> int i = a.get_it();
> int i = a.value = 100;
> -> a.set_it(100);
> -> int i = a.get_it();
>
> For the declaration I'm thinking of something like:
>
> boost::property<
> boost::read<int,A,&A::get_it>,
> boost::write<int,A,&A::set_it>
> > value;
>
> * it doesn't matter whether read<> or write<> comes first
> * if write<> is missing, the property is read-only
> * if read<> is missing, the property is write-only
>
> Is there any interest in this? I do have an implementation
> lying around. I can have it uploaded within a few days
> (have to boostify the thing...).
>
> Geurt
>
I'd certainly like to see what interface can you achieve.
The concept is well known, but good-looking interfaces have always elude us
(that's why it isn't common practice already).

However, I'm a bit suspicious about the promise, though.
For instance, this straight-forward example looks great but it doesn't work:

> boost::property<
> boost::read<int,A,&A::get_it>,
> boost::write<int,A,&A::set_it>
> > value;

&A::get_it can only be a constant expression if get_it is a 'static' member;
but a static member cannot access a property value.

Anyway, I'd like to see what have you done.

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


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