
Boost : 
From: Reece Dunn (msclrhd_at_[hidden])
Date: 20040524 06:34:44
Peter Dimov wrote:
>It doesn't matter. Properties represent degrees of freedom. They don't
>describe dependent data well.
>
>As a relatively simple example, consider a pair of integers (x, y) that has
>an invariant of x*x + y*y = 25, and try to move from (3, 4) to (4, 3) by
>using the X and Y properties.
Since the invariant is on both variables, neither can be set independant of
each other, since you'd assume that changing one would invalidate the
invariant. Therefore, the properties must be *readonly* to prevent
modification. You'd have a function to set both values at the same time
(e.g. moveto).
class coord
{
private:
int x, y;
public:
inline int get_X(){ return( x ); }
inline int get_Y(){ return( y ); }
inline void moveto( int x_, int y_ )
{
assery(( x_ * x_ ) + ( y_ * y_ ) == 25 ); // invariant
x = x_;
y = y_;
}
public: // data access
property_readonly< int, &get_X > X;
property_readonly< int, &get_Y > Y;
public:
// ...
};
Regards,
Reece
_________________________________________________________________
It's fast, it's easy and it's free. Get MSN Messenger today!
http://www.msn.co.uk/messenger
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk