Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: David Brownstein (dbrownstein_at_[hidden])
Date: 2009-10-21 17:17:45

You have nailed several important points. Yes, for "private" setters and
getters a class name is required so that the class can be a friend. I also
share your belief that using function-style accessors rather than assignment
is preferable.

I'm attaching an include file that contains a Property class implementation
that supports this example notation:

struct TestClass
    Alpha( 'a' ),
    Amount( 1001 ),
    AmountSetOnly( 1024 ),
    NumberGetOnly( 4096 )

  Property<bool> IsCreditCard;
  Property<int> Count;
  Property<int> Index;
  Property<char> Alpha;

  Property<int, reveal, conceal, TestClass> Number;
  Property<int, reveal, not_used> Amount;
  Property<int, not_used, reveal > AmountSetOnly;
  Property<int, conceal, not_used, TestClass> NumberGetOnly;

Here "reveal" is analogous to "public" and "conceal" to private. I'm also
attaching a test file, so it should be easy to build and see that this


-----Original Message-----
From: boost-bounces_at_[hidden] [mailto:boost-bounces_at_[hidden]]
On Behalf Of Stefan Strasser
Sent: Tuesday, October 20, 2009 8:16 PM
To: boost_at_[hidden]
Subject: Re: [boost] [property] interest in C# like properties for C++?

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
> should be; I think that ideally a property is a declarative expression
> 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
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
property syntax.
so instead of...

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

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

        int I = x.count(); you can exchange the property object with accessor functions at a
time, when you need non-trivial properties.
Unsubscribe & other changes:

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