Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Edward Diener (eldiener_at_[hidden])
Date: 2009-10-22 23:20:50
Stefan Strasser wrote:
> Am Friday 23 October 2009 01:41:57 schrieb Sid Sacek:
>>>> [ Edward Diener wrote: ]
>>>> Manipulating a reference property would be done purely through
>>>> accessing the property. Accessing a reference property returns a T & or
>>>> a T const & depending on whether the property is const or not. In the
>>>> case where a T & is returned the reference property is read/write if T
>>>> itself is not const, since you can manipulate T through the reference,
>>>> whereas in the case where T const & is returned ( or where T & is
>>>> returns but T is itself const), the reference property is read only.
>> Who says that's how properties work? That just happens to be your version
>> of the implementation details.
> I don't understand what a "reference property" is supposed to be. a property
> getter can return a reference (if it chooses to do so, not in general, since
> there may not be an underlying data member), but what is a reference
In my implementation a "reference property" is a property whose getter
returns a reference to the type of the property. A reference property
does not have a setter. The actual backing data for a "reference
property" can be a value type itself or a reference. The type T of a
reference property does not need to be copy constructible.
This is as opposed to what most people, and other language
implementations, posit as a "property", which is generally a value type,
meaning that a value is returned by the getter and a value is passed to
the setter, of the particular type. The type T of a value type property
does need to be copy constructible in order to pass the value back and
My own reasons for bifurcating the notion of a "property" between the
more common value type property and the reference type property is
because I do no think a clean implementation of the "property" concept
can be done in C++ which allows either a reference or a value to be
returned from the same C++ property implementation.
I am sorry I have not posted my own "property" implementation anywhere
yet, but I am still working on some other "property" issues which are
important to me ( besides trying like everyone else to make a living as
a software designer/programmer ).
I originally added my comments about a "reference" type property
because a poster in this thread felt that one could not implement this
without language support and I do not believe that is the case, and
wanted to explain in general how one could at least theoretically
implement a "reference property".
In a way I am arguing for the notion that a single implementation of the
"property" concept, in other words a single template class which
implements a C++ "property", while desirable from the point of view of
usability, may not be practical from the point of view of flexibility
and an end user's needs.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk