Boost logo

Boost :

Subject: Re: [boost] the best possible c++ properties (implementation).
From: Christopher Jefferson (chris_at_[hidden])
Date: 2010-03-01 12:19:30


On 1 Mar 2010, at 16:58, Germán Diago wrote:

> Hello. I've been trying hard to implement the best possible properties
> sytem in c++ (version 0x).
>
> For now, I'm quite satisfied with the result, but it can be improved a little.
>
> The properties are implemented in a header called (surprisingly!) Property.hpp
>
> Classes:
>
> template TROProperty and TRWProperty for trivial properties, which are
> those which you can use very straightforward without defining setters
> or
> getters and it stores the property value inside.
>
> templates RWProperty and ROProperty, for which you need to define a
> storage (if needed) and getters and setters.
>
> FEATURES:
>
> - You can define a getter as a function that returns *ANYTHING* and it
> will deduce parameters, constness and everything it needs.
> - You can define a setter as a function that returns void and takes
> one parameter. The deduction machinery will do the rest.
>
> So, for trivial properties there is little to explain:
>
> class Person {
> public:
> TROProperty<unsigned int> Age;
> Person(int age) : Age(age) {}
> };
>
> int main(int argc, char * argv[])
> {
> Person p(26);
> cout << p.Age << endl;
> }

How is this any different from:

> class Person {
> public:
> unsigned int Age;
> Person(int age) : Age(age) {}
> };
>
> int main(int argc, char * argv[])
> {
> Person p(26);
> cout << p.Age << endl;
> }

?

Chris


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