Boost logo

Boost :

From: Dragan Milenkovic (tyrant_at_[hidden])
Date: 2002-05-11 15:32:27


Hello,

I am new to this list... is there a search engine or archive
for this mailing list?

And now to get on with my nonsense... I wanted to create some
utilities for get/set member functions. I was wondering why this has
not found its place in the boost libraries.
What I mean is... (the common way):

class Foo {
public:
    int get_x() const;
    void set_x(int new_val
    // or int x() and void x(int) as in std::

private:
    int x;
};

And x doesn't even have to exist. It can be something abstract...
The user's code is then full of something like
    foo.set_x(foo.get_x() + 10);

I have considered something like this:

class Foo {
public:
    Member x;

    Foo() : x(this, &Foo::get_x, &Foo::set_x) {}

private: // or protected
    int get_x(); // and have these virtual
    void set_x(int);
};

Class Member will call the appropriate get/set methods, and the user
can access x as if it was "int x". Someone told me there is language
support for this in C#, but that is of no use to me.

What I am actually trying to do is to ease the creation of such
classes as Member in this case. At least I think it would be useful
when one class needs to observe the change of its property (then
Member holds the value, and only calls x_changed() on change), which
is like the Observer design pattern but in this special case.

So, I need reasons why this is bad, unnecessary, ugly, stupid, slow
and will eventually result in Evil triumphing over Good.

Thank you

-- 
Dragan Milenkovic

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