Boost logo

Boost :

From: Geurt Vos (G.Vos_at_[hidden])
Date: 2002-02-13 04:01:11


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


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