Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-10-21 00:02:23

Stefan Strasser wrote:
> 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();

I do not believe this is the right syntax for accessing properties. The
idea of a "property" is that one uses syntax to access it as if it were
a data object, while it still has the backing of a function to provide

Boost list run by bdawes at, gregod at, cpdaniel at, john at