Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Stefan Strasser (strasser_at_[hidden])
Date: 2009-10-20 23:16:05


Am Wednesday 21 October 2009 02:07:19 schrieb David Brownstein:
> Hi,
> I've been thinking about adding properties to C++ for some time, and I've
> written several different Property<T> classes, so I've been following this
> discussion with great interest. IMO C# properties are not as useful as they
> should be; I think that ideally a property is a declarative expression that
> automatically generates getter and/or setter code.
>
> For example I've been experimenting with a syntax that looks like this:
>
> struct Example
> {
> explicit Example( std::string& strName):
> name( strName ),
> count( 0 )
> {
> }
>
> Property< std::string, public_get, private_set> name;
> Property< int, public_get, public_set> count;
> };

ok, I can see the benefit of that, and it solves the trivial-property-problem
much better than my TRIVIAL_PROPERTY macro. but wouldn't you need an
additional template argument "Example" so you could be-friend "Example" to
enable private access?

however, I would keep accessing the property compatible to the established C++
property syntax.
so instead of...

> x.count = 5;
>
> int I = x.count;

...Example::count would be a function object and you'd write...

        x.count(5);
        int I = x.count();

...so you can exchange the property object with accessor functions at a later
time, when you need non-trivial properties.


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