Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Stewart, Robert (Robert.Stewart_at_[hidden])
Date: 2009-10-21 15:04:28

Stefan Strasser wrote:
> Am Wednesday 21 October 2009 19:26:55 schrieb Sid Sacek:
> > The C# language is very clear about what properties are,
> > why they're part
> > of the language, and how they're used.
> if we were discussing the definition of a new language, I
> might agree with you.

You're discussing the addition of a feature not in the language. It may as well be a new language.

> but this is C++. there is no point in a boost library that no
> one would use
> because using it results in public(!) class interfaces that
> differ from any
> widely used practice AND the standard library.

That's a big leap.

> the C# properties syntax has its benefits. having two
> syntaxes in parallel
> does not. so I wouldn't recommend using the property library
> in public interfaces. but that's its only intended use.

The reason we don't use public data members is because it violates encapsulation. The whole point of properties is that client code can be written *as if* there are public data members. The implementation can forward to functions if and *when* necessary without forcing a change in client code.

> changing the standard library to use properties instead of
> accessor functions
> isn't an option. so why should another library, that is
> intended for eventual standardization, use properties?

I don't share that opinion. If we had properties in the standard library, it could well be that various classes would take advantage of them. The properties might be wired to use the existing accessors and mutators, for example, so that they are purely syntactic sugar without affecting existing clients.

> Am Wednesday 21 October 2009 15:20:23 schrieb Matt Chambers:
> > I don't agree that what you call C++ properties are
> > standard or widely
> > used. I think the get/set prefix is probably just as widely
> > used (just
> so there are 2 different standards, let's introduce a 3rd one?

If the existing approaches aren't as useful or convenient, of course.

> > not in boost or std). Even in cases where one does find both get/set
> > properties in the style you say is standard, X() and X(value), the
> > X(value) function almost never returns X& (with both const
> > and non-const overloads)
> many properties can't return a reference to their value

In those cases in which it is possible and appropriate, and such functions don't do so, they violate your "standard," don't they?

> > . This means that it can't be used in a chain of assignment
> > operations like A.X(B.X(5)) which incidentally looks awful
> > compared to A.X = B.X = 5.

A.X() = B.X() = 5 isn't horrible, but A.X = B.X = 5 is what one expects when one thinks of "properties."

Rob Stewart robert.stewart_at_[hidden]
Software Engineer, Core Software using std::disclaimer;
Susquehanna International Group, LLP

IMPORTANT: The information contained in this email and/or its attachments is confidential. If you are not the intended recipient, please notify the sender immediately by reply and immediately delete this message and all its attachments. Any review, use, reproduction, disclosure or dissemination of this message or any attachment by an unintended recipient is strictly prohibited. Neither this message nor any attachment is intended as or should be construed as an offer, solicitation or recommendation to buy or sell any security or other financial instrument. Neither the sender, his or her employer nor any of their respective affiliates makes any warranties as to the completeness or accuracy of any of the information contained herein or that this message or any of its attachments is free of viruses.

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