Boost logo

Boost :

Subject: Re: [boost] [property] interest in C# like properties for C++?
From: Olaf van der Spek (olafvdspek_at_[hidden])
Date: 2009-10-23 10:27:57

On Fri, Oct 23, 2009 at 3:40 PM, Edward Diener <eldiener_at_[hidden]> wrote:
>> Maybe I should've said class reference. Take std::string for example.
>> I'd be very interested if you've got code that supports for example
>> name.size() where name is your reference property class. name->size()
>> is no problem, but I'd like to have name.size().
> I understand your point, and you are right, and this is a notational
> weakness as compared with accessing the data directly.
> I don't believe that one can define a dot ( '.' ) operator in C++ but maybe
> there is a metaprogramming way to hijack the dot operator. If there is I
> would be glad to use it.
> Actually I have rejected defining the -> operator for my reference
> properties, because -> implies a pointer in standard C++ terminology and I
> do not think of reference properties "pointing" to their type object.
> Instead my reference properties have currently no built-in forwarder
> operator to the actual type object. One could currently use the more
> laborious form of:
> propertyReference<std::string> name;
> std::string & avar = name; // read/write property reference getter
> avar.size() = 10; // or
> std::string::size_type sz(avar.size());


> or one could use my getter member function so one could write:
> propertyReference<std::string> name;
> name.getReference.size() = 10; // or
> std::string::size_type sz(name.getReference.size());


> Using a member function rather than an operator in this case is just a
> little more inconvenient.

For me, the access syntax of properties is *the* reason for using them.
Otherwise you might as well just add string& name() and void
set_name(const string&) functions to your class.
What are your goals/reasons to use properties?

> My member function is actually currently called "getValue" for my reference
> property but I have decided that it is a confusing name since one is really
> getting a reference, and have changed it to "getReference".

How about just get()?

> -----------------------------------------------------------------------
> "So really one would not a separate template class to
> support reference properties."
> This was originally mistyped by me and should have been:
> "So really one would need a separate template class to
> support reference properties."
> But I think you read through my error anyway without any problems.

Probably. ;)

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